我使用view.getBackground()
来获取EditText
的背景,然后将其再次设置为该EditText
,但问题是背景类似于edittext默认背景,不同之处在于其他editText默认背景在具有焦点时变为绿色,但我获取的背景不会改变其颜色!(EditText是在材料设计中引入的android默认editText)。
发布于 2015-10-21 05:48:37
您可以创建自己的自定义EditText。
edit_text.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/textfield_default" />
<item
android:state_window_focused="false"
android:state_enabled="false"
android:drawable="@drawable/textfield_disabled" />
<item
android:state_pressed="true"
android:drawable="@drawable/textfield_pressed" />
<item
android:state_enabled="true"
android:state_focused="true"
android:drawable="@drawable/textfield_selected" />
<item
android:state_enabled="true"
android:drawable="@drawable/textfield_default" />
<item
android:state_focused="true"
android:drawable="@drawable/textfield_disabled_selected" />
<item
android:drawable="@drawable/textfield_disabled" />
</selector>
在你的activity_main.xml中定义EditText。
<EditText
android:id="@+id/edit1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/edit1_text"
android:inputType="text"
android:background="@drawable/edit_text" />
您将看到这种类型的EditText。
根据您的需要对其进行自定义。
https://stackoverflow.com/questions/33251582
复制相似问题