所以我在我的应用程序中有一个listview,它似乎是AppTheme值" colorControlHighlight"将该列表视图中的纹波和onclick行的颜色更改为(蓝色)。但是我创建了一个listview,其中包含与小部件颜色相关的相同xml属性,由于某种原因,纹理和印刷颜色仍然是默认颜色(白色)。如果我在我的小部件上更改列表视图的android:listselector
属性,它可以正常工作,但它不会起作用,并且涟漪效应消失了。它是如何行动的;在我更改listselector之后它会保持蓝色,除非我按下列表中的另一行。这不是我想要的(这是因为我还没有设置onclick动作?或者这个属性是如何设计的?)。任何帮助将不胜感激。
这是我的应用活动列表视图
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/AppUrlList"
android:background="@color/dark_black"
android:layout_gravity="center_horizontal"
android:dividerHeight="1px"
android:divider="@color/faded_blue"
android:clickable="true"
/>
现在这是我的小部件列表视图
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:dividerHeight="2px"
android:divider="@color/faded_blue"
android:background="@color/black"
android:id="@+id/WidgetListView"
android:layout_gravity="center_horizontal" />
现在这是我的apptheme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlNormal">@color/faded_blue</item>
<item name="colorControlActivated">@color/bright_blue</item>
<item name="colorControlHighlight">@color/bright_blue</item>
感谢您提出改善我的问题的建议
答案 0 :(得分:1)
我想通了我必须这样做:
app_list_item.xml
<TextView
android:id="@+id/AppListTextViewGreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/List_Hint"
android:gravity="center"
android:background="@drawable/list_background_green"
style="@style/liststyleGreen"
/>
然后在list_background_green.xml
中 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@color/faded_green" />
<item android:state_pressed="true" android:drawable="@color/faded_green"/>
<item android:drawable="@color/black" />
</selector>
state_pressed用于定义按下列表项时的颜色(显然)
,默认背景为黑色。
这适用于我的小部件,而在应用主题中设置默认颜色并没有改变我的小部件中的颜色。
编辑:忘了把涟漪选择器放在这里,在这里,我还将包括如何让它在api 21上面的版本上运行。
您必须将涟漪选择器命名为与列表选择器相同的名称。所以你要制作另一个名为“list_background_green”的xml,但是把它放在drawable-v21文件夹中。这个文件夹可能不存在,所以右键单击android studio中的res文件夹,然后单击explorer中的show,然后创建drawable-v21文件夹并将相同的命名xml放在那里。这是一个例子。
可绘制-V21 / list_background_green.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/bright_green">
<item>
<selector>
<item android:state_selected="true">
<color android:color="@color/transp_green" />
</item>
<item android:state_activated="true">
<color android:color="@color/transp_green" />
</item>
<item android:state_pressed="true">
<color android:color="@color/transp_green" />
</item>
<item>
<color android:color="@color/semi_trans_black" />
</item>
</selector>
</item>
你要小心这个值是多么透明。
<color android:color="@color/semi_trans_black" />
我无法弄清楚为什么选择器没有出现一段时间然后意识到如果这个值太透明它会使波纹不显示。我无法解释为什么如果有人能够做到,只是警告人们,因为我花了一段时间才弄明白这是原因。该值是列表中每个textview的默认背景,因此选择器可能会继承它的透明度,尽管这并没有多大意义。我只需要在我的appwidget上执行此操作,原因超出了我目前的理解。在我的常规应用列表视图中,我不需要执行任何操作。我怀疑小部件是从系统继承他们的主题,但我不确定。
欢呼,希望这有助于某人。