Edittext 在Activity中無法獲取焦點問題
經排查發現是根控件設置問題
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
tools:context=".activity.MainActivity">
android:descendantFocusability="blocksDescendants"
android:descendantFocusability
該屬性是當一個爲view獲取焦點時,定義viewGroup和其子控件兩者之間的關係。
屬性的值有三種:
beforeDescendants:viewgroup會優先其子類控件而獲取到焦點
afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點
記錄一下,便於理解