Fre*_*lia 13 android colors button
我正在使用Android Studio.我需要更改单选按钮的颜色,将Button Tint Color值更改为我需要它在预览上工作的那个,但每当我在设备上启动应用程序时,按钮是标准的绿色/蓝色颜色.
这是某种设备API级问题吗?如果是这样,是否可以更改旧设备的颜色?
use*_*401 21
在阅读了@ Ranjith的回答后,我做了一点挖掘,这似乎有效.只需将其添加到AppTheme即可.
//red is the color of the pressed state and activated state
<item name="colorControlActivated">@android:color/holo_red_light</item>
//black is the color of the normal state
<item name="colorControlNormal">@android:color/black</item>
Run Code Online (Sandbox Code Playgroud)
我的问题是你如何以编程方式执行此操作,因为我有动态单选按钮?
这可以通过两种方式完成(支持pre-Lollipop):
用途AppCompatRadioButton:
AppCompatRadioButton radioButton;
// now use following methods to set tint colour
radioButton.setSupportButtonTintMode();
radioButton.setSupportButtonTintList();
Run Code Online (Sandbox Code Playgroud)将此作为样式应用于您RadioButton的XML:
<style name="RadioButton.Login" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:textColor">@android:color/white</item>
<item name="buttonTint">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)RadioButton raPrivate = (RadioButton) layout.findViewById(R.id.radioPrivate);
int textColor = Color.parseColor(#000000);
raPrivate.setButtonTintList(ColorStateList.valueOf(textColor));
Run Code Online (Sandbox Code Playgroud)
如果要更改颜色,但不更改整个应用程序的colorControlActivated和colorControlNormal,则可以通过创建新样式来仅针对单选按钮覆盖应用程序:
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:theme="@style/RadioButtonTheme"
android:id="@+id/radioButton"/>
<style name="RadioButtonTheme" parent="@style/AppTheme">
<item name="colorControlActivated">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorPrimaryDark</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26135 次 |
| 最近记录: |