【发布时间】:2014-04-04 14:50:01
【问题描述】:
我们如何更改 ActionMode 的布局或背景?有方法actionMode.getCustomView();但总是返回 null 。有什么建议吗?
【问题讨论】:
标签: android android-layout android-actionmode
我们如何更改 ActionMode 的布局或背景?有方法actionMode.getCustomView();但总是返回 null 。有什么建议吗?
【问题讨论】:
标签: android android-layout android-actionmode
你可以通过styles.xml用这个属性来改变它
<item name="android:actionModeBackground">@drawable/actionbar_background</item>
<item name="actionModeBackground">@drawable/actionbar_background</item>
尚不支持以编程方式更改它的 ASAIK
【讨论】:
我想让这个答案更清楚。首先在您的可绘制文件夹中创建自定义背景“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>
【讨论】:
如果你想改变ActionMode的背景,你应该使用actionMode.setCustomView(View yourView),然后你可以将yourView变量传递给方法。
【讨论】: