2012CSDN博客之星評選正式上線 2000元大獎征異構開發博文 Q14年互聯網產品進化史
項目中有個檢索功能,頁面上有個EditText輸入框,打開頁面后,焦點默認在EditText上,這樣的話軟鍵盤默認就會顯示出來,占據大半個屏幕。
后來想辦法將這個給去掉了,原先考慮着將焦點賦給頁面上的其他組件(頁面上還有時間選擇組件、按鈕組件等),方法如下:
<EditText android:id="@+id/topical_content" android:layout_width="260dip" android:layout_alignParentLeft="true" android:layout_height="wrap_content" android:textSize="12sp" android:layout_toLeftOf="@id/topical_image" android:hint="請輸入主題" android:singleLine="true" android:nextFocusUp="@+id/其它控件ID" android:nextFocusLeft="@+id/其它控件ID">
</EditText>
另一種方法是在EditText前面放置一個看不到的LinearLayout,讓它率先獲取焦點,代碼如下:
<LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/>
還有一種方法是在manifest中設置對activity的控制(此方法從網上找的,效果沒有試驗,不知道可不可以,列出來給大家參考下)
<activity ... android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
本人項目中用的是第二種方法,即在EditText前面加了一個Linearlayout,讓它讓率先獲取焦點,實現了我想要的結果。