在ContextualActionMode中为不同的主题更改“突出显示”的颜色

时间:2017-05-14 18:56:43

标签: android textview android-actionmode mobile-development

简短说明:我们正在为该大学开发Android应用程序。在第一个屏幕上是一个列表。此列表由包含大量TextView的ListView生成。以下代码位于CustomListAdapter中:

@Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v = super.getView(position, convertView, parent);//let the adapter handle setting up the row views
        v.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));

        if (mSelection.get(position) != null) {
            v.setBackgroundColor(mContext.getResources().getColor(android.R.color.holo_blue_light));
        }

        return v;
    }

我发现if语句中的行:v.setBackgroundColor(mContext.getResources().getColor(android.R.color.holo_blue_light));设置列表中所选项的颜色。有没有办法改变不同主题的颜色?所以它在一个主题中就像这个(蓝色),但是橙色或者是不同主题的东西。

我尝试使用不同的解决方案:

<style name="BlackTheme" parent="Theme.AppCompat">
    <item name="colorAccent">@android:color/holo_orange_dark</item>
    <item name="android:actionModeStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="Base.Widget.AppCompat.ActionBar">
    <item name="android:background">@android:color/holo_orange_light</item>
</style>

for android:background我使用了多个不同的属性,但直到现在它们都没有工作。

我也尝试过设置  v.setBackgroundColor(mContext.getResources().getColor(android.R.color.holo_blue_light));来  v.setBackgroundColor(mContext.getResources().getColor(R.color.selectedItem));,此颜色设置如下:
<color name="selectedItem">?attr/selectableItemBackground</color>
我的风格包含<item name="android:selectableItemBackground">@android:color/holo_orange_light</item>行。这也行不通,因为它会抛出类型“android.content.res.Resources $ NotFoundException:资源ID#0x7f0b0054类型#0x2无效”的错误

提前致谢:)

0 个答案:

没有答案