material-design - 在材质设计中,如何使用appCompat定制上下文操作栏

  显示原文与译文双语对照的内容
50 1

MainActivity.java

我在此类中实现了 MultiChoiceModeListener,下面是代码:

listView 上:

listView.setMultiChoiceModeListener(MainActivity.this);
listView.setChoiceMode(listView.CHOICE_MODE_MULTIPLE_MODAL);
 @Override
 public boolean onActionItemClicked(ActionMode arg0, MenuItem arg1) {
 switch (arg1.getItemId()) {
 case R.id.save:
//Close CAB
 arg0.finish();
 return true;
 case R.id.saveto:
//Close CAB
 arg0.finish();
 return true;
 default:
 return false;
 }
 }
 @Override
 public boolean onCreateActionMode(ActionMode arg0, Menu arg1) {
 arg0.getMenuInflater().inflate(R.menu.save_menu, arg1);
 return true;
 }
 @Override
 public void onDestroyActionMode(ActionMode arg0) {
 listadaptor.removeSelection();
 }
 @Override
 public boolean onPrepareActionMode(ActionMode arg0, Menu arg1) {
 return false;
 }
 @Override
 public void onItemCheckedStateChanged(ActionMode arg0, int arg1, long arg2,
 boolean arg3) {
 final int checkedCount = listView.getCheckedItemCount();
 arg0.setTitle(checkedCount +""+getResources().getString(R.string.selected));
 listadaptor.toggleSelection(arg1);
 }

style.xml

 <style name="AppTheme.Base" parent="Theme.AppCompat.Light">
 <item name="colorPrimary">@color/colorPrimary</item>
 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
 <item name="colorAccent">@color/White</item>
 <item name="android:windowNoTitle">true</item>
 <item name="windowActionModeOverlay">true</item>
 <item name="windowActionBar">false</item>
 <item name="actionModeStyle">@style/LStyled.ActionMode</item>
 </style>
 <!-- Application theme. -->
 <style name="AppTheme" parent="AppTheme.Base">
 <!-- All customizations that are NOT specific to a particular API-level can go here. -->
 </style>
 <style name="LStyled.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
 <item name="background">@color/colorPrimary</item>
 </style>
 <style name="ActionBarThemeOverlay" parent="Theme.AppCompat.Light">
 <item name="android:textColorPrimary">#fff</item>
 <item name="colorControlNormal">#fff</item>
 <item name="colorControlHighlight">#3fff</item>
 </style>
 <style name="HeaderBar">
 <item name="android:background">#009688</item>
 <item name="android:textStyle">bold</item>
 </style>
 <style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light">
 <item name="android:textColor">#000</item>
 </style>

下面是我的屏幕截图:

this is my material design screen

actionmode material design screen

在第二个屏幕截图中,你可以看到,actionmode背景是白色,文本颜色也是白色。我想把它改成第一个屏幕截图颜色。

时间:原作者:0个回答

146 5

你可以通过属性 actionModeStyle 更改 ActionMode 背景:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
. . ..
. . ..
 <item name="actionModeStyle">@style/LStyled.ActionMode</item>
</style>
<style name="LStyled.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
 <item name="background">@color/color_action_mode_bg</item>
</style>

当然,你需要定义名为 color_action_mode_bg的颜色:

<color name="color_action_mode_bg">#009688</color>

还有其他事情你也可以改变。例如:

<item name="titleTextStyle">...</item>
<item name="subtitleTextStyle">...</item>
<item name="height">...</item>

若要更改 SAVESAVETO的文本颜色,请将以下内容添加到 AppTheme.Base:

<item name="actionMenuTextColor">@color/color_action_mode_text</item>
原作者:
71 3

AppTheme.Base 风格中使用 actionModeBackground

<item name="actionModeBackground">@color/colorPrimary </item> (or)
<item name="android:actionModeBackground">@color/colorPrimary </item>
原作者:
...