我正在寻找有关上下文操作栏(CAB)的样式信息。实际上,我只需要更改文本的颜色。
我正在寻找有关上下文操作栏(CAB)的样式信息。实际上,我只需要更改文本的颜色。
要更改上下文操作栏中文本的颜色/等等:
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
//mode.setTitle("Contextual Action Bar"); (replace this call)
TextView tv= (TextView)getLayoutInflater().inflate(R.layout.contextual_title, null);
tv.setText("Contextual Action Bar");
mode.setCustomView(tv);
在 layout/contextual_title.xml 文件中,包含有一个 TextView 控件,你可以设置所需的颜色、大小和样式等。
实际上,上下文操作栏中几乎所有内容都可以进行样式设计。唯一的问题是查找“contextual”一词没有明确的结果。相关的样式特性都被称为“actionMode...”。以下是一些我使用过的(定义在我的主题中)。
<item name="android:actionModeCloseDrawable">@drawable/check</item>
<item name="android:actionModeCutDrawable">@drawable/ic_menu_cut_holo_dark</item>
<item name="android:actionModeCopyDrawable">@drawable/ic_menu_copy_holo_dark</item>
<item name="android:actionModePasteDrawable">@drawable/ic_menu_paste_holo_dark</item>
<item name="android:actionModeSelectAllDrawable">@drawable/ic_menu_selectall_holo_dark</item>
<item name="android:actionModeBackground">@drawable/contextual</item>
<item name="android:actionModeCloseButtonStyle">@style/MyCloseButton</item>
<!-- these change the press backgrounds for the vanilla actionBar and for search -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:selectableItemBackground">@drawable/bar_selector</item>
<item name="android:actionBarItemBackground">@drawable/bar_selector</item>
<!-- these were defined in platform/.../data/res/values/... but Eclipse didn't recognize them -->
<!--? item name="android:actionModeShareDrawable">@drawable/icon</item -->
<!--? item name="android:actionModeFindDrawable">@drawable/icon</item -->
<!--? item name="android:actionModeWebSearchDrawable">@drawable/icon</item -->
<!-- item name="android:actionModeBackground">@drawable/red</item -->
<!-- and finally -->
<style name="MyCloseButton" parent="android:style/Widget.ActionButton.CloseMode">
<item name="android:background">@drawable/bar_selector</item>
</style>
现在它可以工作了,但你必须将其输入到values/styles.xml(而不是values-v#/styles.xml),并将其输入到通用的(非API特定的)标签中。
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionModeCloseDrawable">@drawable/ic_launcher</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity_layout);
// these lines can occur anywhere so long as you've already
// called "setContentView()" on the activity. The theme
// you set here will apply to the action mode, but not to
// the activity.
setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);
startSupportActionMode(myActionModeCallback);
}