gpt4 book ai didi

android - 启动 ActionMode 时的两个操作栏

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:09 24 4
gpt4 key购买 nike

我有以下 Activity 布局:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
style="@style/DrawerLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ui.activity.MyActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:background="@color/black"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/ToolbarTitle"
app:contentScrim="@color/primary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/ThemeOverlay.AppCompat.Light"/>

</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<my.package.ui.widget.MyHeaderWidget
android:id="@+id/deal_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="my.package.ui.activity.MyHeaderBehavior"/>

<include layout="@layout/content_list"/>
</android.support.design.widget.CoordinatorLayout>

<include layout="@layout/navigation_view"/>

</android.support.v4.widget.DrawerLayout>

它用于折叠工具栏+抽屉导航+标题动画和子标题(在标题小部件中)。一切都很好,直到我尝试启动 ActionMode 以启用多选。

我通过调用:

    mActionMode = mCollapsingToolbarLayout.startActionMode(mActionModeCallback);

问题是我最终有两个操作栏(带有两个箭头):

See the screenshot

黑色的是我期待的那个,白色的是在我启动 ActionMode 时添加的。

我做错了什么吗?

编辑

AndroidMaifest

    <activity
android:name=".ui.activity.MyActivity"
android:label="@string/title_activity"
android:theme="@style/MyTheme">
</activity>

styles.xml

<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@drawable/window_background_gray</item>
<item name="android:colorBackground">@color/app_background</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorAccent">@color/accent</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="android:textAppearanceButton">@style/Theme.ButtonTextAppearance</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

EDIT2

如果您想测试这个问题,您可以使用 ScrollingActivity 示例代码在 Android Studio 中创建一个新项目。根据您的想法修改主题,然后在按下 FAB 时启动操作模式,将以下对象作为 ActionMode.Callback 传递给 startSupportActionMode:

private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_scrolling, menu);
return true;
}

// Called each time the action mode is shown. Always called after onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false; // Return false if nothing is done
}

// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
mode.finish();
return true;
default:
return false;
}
}

// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
}
};

最佳答案

如果您使用工具栏,这 3 行就足够了:

 <style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item> <!-- This is the important line -->
</style>

记得在文件 styles 和 styles(v21) 中添加它

关于android - 启动 ActionMode 时的两个操作栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37629856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com