<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<AutoCompleteTextView
android:id="@+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="@drawable/black_rounded_borders" />
</RelativeLayout>
我添加了无用的 LinearLayout 只是为了避免在启动 Activity 时初始关注 AutoCompleteTextView
可绘制/black_rounded_borders.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#FFFFFFFF" />
<stroke
android:width="2dp"
android:color="@color/selector_black_border" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
颜色/selector_black_border.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="#FF269ff5"/>
<item android:state_pressed="true" android:color="#FF269ff5"/>
<item android:state_selected="true" android:color="#FF269ff5"/>
<item android:state_focused="false" android:color="#FF000000"/>
<item android:state_pressed="false" android:color="#FF000000"/>
<item android:state_selected="false" android:color="#FF000000"/>
</selector>
活动
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);
Log.d("hasFocus", autoComplete.hasFocus() + "");
Log.d("isSelected", autoComplete.isSelected() + "");
Log.d("isPressed", autoComplete.isPressed() + "");
//All the above are false
}
尽管与蓝色(#FF269ff5)颜色相关的所有状态都是错误的。我仍然得到蓝色的边框。此外,如果我更改color/selector_black_border.xml文件中的状态顺序,比如先全部为假,然后为真,那么我会得到黑色边框。它就像只有第一种颜色有效。
我错过了什么?
谢谢你。