開發中,發現第一次進入頁面時光標就會出現在頁面的第一個edittext中,解決思路是:
在edittext的父布局中加入兩行代碼奪取焦點
<com.zhy.autolayout.AutoLinearLayout android:layout_width="match_parent" android:layout_height="50px" android:background="@android:color/white" android:orientation="horizontal" android:gravity="center_vertical" android:focusable="true" android:focusableInTouchMode="true" > <EditText android:id="@+id/et_phoneNumber" style="@style/Edit_text" android:layout_width="0dp" android:layout_weight="1" android:hint="用戶搜索" android:textColorHint="@color/setPageBackgroudColor" android:textColor="@android:color/darker_gray" /> <ImageView
另外hint的文字是在用戶開始輸入的時候才會消失,不是在獲取焦點的時候消失,這個細節居然一直沒注意到。