如何自定义在材料设计使用appCompat的上下文操作栏 [英] how to Customize the Contextual Action Bar using appCompat in material design

查看:133
本文介绍了如何自定义在材料设计使用appCompat的上下文操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MainActivity.java

MainActivity.java

我实现MultiChoiceModeListener在这个类及以下为code:

i implemented MultiChoiceModeListener in this class and below is code:

在列表视图:

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.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>

下面是我的截图:

below is my screenshots:

您可以看到两个截图,在第二个屏幕,actionmode背景为白色和文本颜色也是白色的..我想将其更改为第一屏颜色,这是在顶部。

you can see both screenshots, in second screenshot, actionmode background is white and text color is also white.. i want to change it to first screenshots color which is in top.

推荐答案

您可以修改 ActionMode 通过属性背景 actionModeStyle

You can change the ActionMode background through attribute actionModeStyle:

<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

You will of course need to define a color named color_action_mode_bg:

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

有其他的东西,你可以改变。例如:

There are other things you can change as well. Example:

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

要改变文字颜色保存 SAVETO ,以下内容添加到 AppTheme。基本

To change text color of SAVE and SAVETO, add the following to AppTheme.Base:

<item name="actionMenuTextColor">@color/color_action_mode_text</item>

这篇关于如何自定义在材料设计使用appCompat的上下文操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆