【发布时间】:2020-02-04 02:33:14
【问题描述】:
我无法使用设计库如何在此代码中更改颜色 onclick?
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new order"
/>
【问题讨论】:
标签: android
我无法使用设计库如何在此代码中更改颜色 onclick?
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new order"
/>
【问题讨论】:
标签: android
我宁愿在运行时更改颜色,也不愿在选择时添加样式以保持波纹感。在这里,您根据代码级别的选择设置颜色
setBackgroundColor(Color.RED);
查看更多
https://developer.android.com/reference/com/google/android/material/tabs/TabItem
【讨论】:
您是否尝试过使用 xml 颜色选择器?
在drawable目录中创建一个这样的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent" android:state_selected="true"/>
<item android:drawable="@color/colorPrimary"/>
</selector>
在你的 tablayout xml 代码中:
android:background="@drawable/drawable_xml_selector"
我希望这会有所帮助。
【讨论】: