【问题标题】:Android - ActionMode after landscape the Toolbar becomes visible and does not hideAndroid - 横向后的 ActionMode 工具栏变为可见且不隐藏
【发布时间】:2021-12-01 19:50:01
【问题描述】:

我有一个根视图,这个根视图包含一个带有 viewpager 的片段。这是我的内容片段。我更新了这个 ContentFragment 的视图以获取 viewpager 行为。现在,当我为 ContentFragment 的视图激活 ActionMode 时,ActionMode 最初会隐藏根视图的工具栏,这是所需的结果,如下所示:

不幸的是,在横向模式之后,工具栏又变得可见并且没有隐藏。查看下图:

之后,即使我将设备竖直放置,我总是在 ActionMode 中看到以下视图:

而不是这个:(期望的视图)

当我使用这行代码手动隐藏工具栏时:

toolbar.visibility = View.INVISIBLE

或

toolbar.visibility = View.GONE

在根视图中,ActionMode 与 ListView 的第一项重叠,如下所示:

我有

<item name="windowActionModeOverlay">true</item>

在themes.xml 中使用过,我敢肯定。但问题是,为什么 ActionMode 一开始会隐藏 Toolbar,但在横向模式之后,Toolbar 又变得可见并且永远不会隐藏。

【问题讨论】:

    标签: android android-toolbar android-actionmode actionmode


    【解决方案1】:

    我认为这可能是由片段的重新创建引起的。 片段创建操作栏,但是当设备旋转时,片段会重新创建,但操作栏不会在片段重新创建状态下更新,因此工具栏再次显示

    你可能想在创建片段时做这样的事情

    //Write in OncreatFragment
    If (getActivity().getSupportActionBar() != null ) {
    //hide action bar
    //Toolbar should automatically be shown as you said
    } else {
    //Do nothing since this is the start of the fragment.
    }
    

    此外,您应该保存一个布尔值或整数,以便在显示操作栏时重新创建片段时,您将重新创建操作栏

    //Write in OncreatFragment
    If (getActivity().getSupportActionBar() != null ) {
       if (wasActionBarPreviouslyShown) {
       //Receate the action bar this should automatically hide the toolbar
       } else {
       //hide the action bar since it wasn't previously shown toolbar should automatically be shown as you have stated.               }
    } else {
        //Do nothing.
    }
    

    我希望这会有所帮助,即使只是一点点。

    【讨论】:

    • 感谢您的回答。但是将“actionBarSize”设置为工具栏高度解决了我的问题。我刚刚将 @dimen/toolbar_action_mode_height 添加到我的主题中。问题解决了。
    • 很高兴听到这个消息
    【解决方案2】:

    将actionBarSize 固定到工具栏高度解决了我的问题。我刚刚加了

    <item name="actionBarSize">@dimen/toolbar_action_mode_height</item>
    

    我的主题。问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      相关资源
      最近更新 更多