How to change ActionMode background color in Andro

2020-01-27 04:41发布

i am creating an android app in which support level api is 7 so i am using sherlock actionbar. I am using action mode in it. Issue is i want to change the background of action mode. So i have tried

    <item name="android:background">@color/something</item>
    <item name="android:backgroundStacked">@color/something</item>
    <item name="android:backgroundSplit">@color/something</item>

these style solution's available but none of them works. enter image description here

9条回答
做自己的国王
2楼-- · 2020-01-27 05:26

if you want change the color of ActionBar just do this:

 ActionBar bar = getActionBar();
 bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

see the following link for more info

and if you using ActionMode This is the style used for any ActionMode. You'll need to create your own style to customize it

<style name="Widget.ActionMode">
<item name="android:background">?android:attr/actionModeBackground</item>
<item name="android:backgroundSplit">?android:attr/actionModeSplitBackground</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:titleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Title</item>
<item name="android:subtitleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Subtitle</item>
</style>

more info in this site

see this too

Edit

for pre-Honeycomb see this please

maybe this or this helped you

查看更多
干净又极端
3楼-- · 2020-01-27 05:28

I wanna make more clearer this answer. First create custom background "storage_list_header_shape.xml" in your drawable folder.

<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle" >

   <gradient
      android:angle="270"
      android:startColor="@android:color/holo_orange_light"
      android:centerColor="@android:color/holo_orange_dark"
      android:endColor="@android:color/holo_orange_light" />

   <size android:height="3dp" />

 </shape>

Second, create custom style in your style.xml

<style name="customActionModeTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionModeBackground">@drawable/storage_list_header_shape</item>
</style>

Third, call the style in your manifest.

<activity
     android:name="com.javacafe.activities.Main"
     android:launchMode="singleTop"
     android:screenOrientation="sensorLandscape"
     android:theme="@style/customActionModeTheme" >
</activity>
查看更多
萌系小妹纸
4楼-- · 2020-01-27 05:29

This is the style used for any ActionMode, I pulled it from the SDK. You'll need to create your own style to customize it. It's really easy to do. If you've never done anything like this before, you should read through this post on customizing the ActionBar. It explains everything you'll need to know.

<style name="Widget.ActionMode">
<item name="android:background">?android:attr/actionModeBackground</item>
<item name="android:backgroundSplit">?android:attr/actionModeSplitBackground</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:titleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Title</item>
<item name="android:subtitleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Subtitle</item>
</style>
查看更多
登录 后发表回答