layoutにborderを入れる
主にデバッグ用なんですけど。
Viewのオプションではできないっぽい。ので、drawbleな枠を定義して、backgroundにそれを指定する。
drawable/debug_border.xml
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="1dp" android:color="#ff0000" /> <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> </shape>
layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="hogehoge" android:background="@drawable/debug_border" /> </LinearLayout>
EditTextでandroid:focusableInTouchMode="false"にしたらsetErrorがうまく動かなくなったときの対応法。
これはsetErrorで表示されるバルーン的なものがフォーカス時にのみ表示されるという仕様だから。
次にフォーカスについてここで勉強する。超良記事。
たかがフォーカス,されどフォーカス
View#requestFocusFromTouchメソッドを使うと、 タッチモード時でもfocusableInTouchMode属性がfalseのウィジェットに対して、 フォーカスを移動させることができる。
というわけで、コード中の良きところで
requestFocusFromTouch()
を呼ぶべし。