[英]ToggleButton shape not changing
Am trying to make a circular togglebutton with a green background. 我试图用绿色背景制作圆形togglebutton。 i used
我用了
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true">
<solid android:color="@color/material_green_A200" />
</shape>
for defining the shape and then used 用于定义形状然后使用
android:background="@drawable/circlebutton"
to change the shape and color but nothing changes. 改变形状和颜色,但没有任何变化。 it shows up with a no background color or shape but the text is visible
它显示没有背景颜色或形状,但文本是可见的
Try this, 试试这个,
Your activity.xml 你的activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/style_toggle_button" />
</RelativeLayout>
Style Toggle Button(style_toggle_button.xml): 样式切换按钮(style_toggle_button.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/offcirclebutton" android:state_enabled="false"/>
<item android:drawable="@drawable/oncirclebutton" android:state_pressed="true"/>
<item android:drawable="@drawable/oncirclebutton" android:state_checked="true"/>
<item android:drawable="@drawable/oncirclebutton" android:state_focused="true"/>
<item android:drawable="@drawable/offcirclebutton"/>
</selector>
Style OFF(offcirclebutton.xml): 样式OFF(offcirclebutton.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true">
<solid android:color="@android:color/holo_orange_dark" />
</shape>
Style ON(oncirclebutton.xml): 样式ON(oncirclebutton.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true">
<solid android:color="@android:color/holo_green_dark" />
</shape>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.