Question

How can we change the layout or background of an ActionMode ? there is methodactionMode.getCustomView();but always returns null . is there any suggestion?

Was it helpful?

Solution

You can change it through styles.xml with this attribute

 <item name="android:actionModeBackground">@drawable/actionbar_background</item>
 <item name="actionModeBackground">@drawable/actionbar_background</item>

ASAIK changing it programmatically is not yet supported

OTHER TIPS

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>

if you want to change the background of an ActionMode,you should use the actionMode.setCustomView(View yourView),then you can transfer the yourView variable to the method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top