我们如何更改ActionMode
的布局或背景?方法actionMode.getCustomView();
但始终返回null。有什么建议吗?
答案 0 :(得分:7)
您可以使用此属性
通过styles.xml更改它 <item name="android:actionModeBackground">@drawable/actionbar_background</item>
<item name="actionModeBackground">@drawable/actionbar_background</item>
ASAIK尚不支持以编程方式更改
答案 1 :(得分:2)
我想让这个答案更加清晰。首先在drawable文件夹中创建自定义背景“storage_list_header_shape.xml”。
<?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>
其次,在style.xml中创建自定义样式
<style name="customActionModeTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionModeBackground">@drawable/storage_list_header_shape</item>
</style>
第三,在清单中调用样式。
<activity
android:name="com.javacafe.activities.Main"
android:launchMode="singleTop"
android:screenOrientation="sensorLandscape"
android:theme="@style/customActionModeTheme" >
</activity>
答案 2 :(得分:1)
如果您想更改ActionMode
的背景,则应使用actionMode.setCustomView(View yourView)
,然后将yourView
变量转移到该方法。