我有一个片段,背景中有一个图像我希望编辑文本的边框在按下时改变颜色,当它不是但它不起作用我尝试删除背景图像,我得到相同的结果这里是我的代码rounded_edittext:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/focused"
/> <!-- focused -->
<item
android:state_pressed="false"
android:drawable="@drawable/unfocused"
/> <!-- defualt -->
</selector>
聚焦:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#000" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</selector>
重点:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#fff" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
我把它添加到edittext这里:
android:background="@drawable/rounded_edittext"
我怎么能解决这个问题?
尝试使用它而不是android:state_pressed使用android:state_focused。
<item
android:state_focused="true"
android:drawable="@drawable/unfocused"
/> <!-- focused -->
<item
android:state_focused="false"
android:drawable="@drawable/focused"
/>
</selector>
问题出在这里,因为我使用的是选择器而不是形状:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#000" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</selector>