Android requestFocus詳解及實(shí)例
Android requestFocus詳解及實(shí)例
requestFocus的使用
一句話概括:
<requestFocus />: 標(biāo)簽用于指定屏幕內(nèi)的焦點(diǎn)View。
布局資源文件的根節(jié)點(diǎn)可以使用容器控件(如LinearLayout、FrameLayout等),也可以使用非容器控件(如:EditText、TextView等)。對于非容器控件,只能在非容器控件標(biāo)簽中放<requestFocus />標(biāo)簽,表示將當(dāng)前控件設(shè)為焦點(diǎn)。如下代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonRingtone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="設(shè)置來電鈴聲" />
<Button
android:id="@+id/buttonAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="設(shè)置鬧鐘鈴聲" />
<Button
android:id="@+id/buttonNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="設(shè)置通知鈴聲" />
<EditText
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- 當(dāng)前控件處于焦點(diǎn)狀態(tài) -->
<requestFocus />
</EditText>
</LinearLayout>
這樣,當(dāng)進(jìn)入時(shí)edittext就獲取了焦點(diǎn)。
Android requestFocus的使用就講完了。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Android仿拉手網(wǎng)團(tuán)購App產(chǎn)品詳情界面效果
這篇文章主要介紹了Android仿拉手網(wǎng)團(tuán)購App產(chǎn)品詳情界面效果,代碼簡單易懂,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05
解決Android Studio導(dǎo)入項(xiàng)目非常慢的辦法
在使用Android studio的時(shí)候常常遇到這樣的問題,從其他地方導(dǎo)入項(xiàng)目,Android studio呈現(xiàn)非常慢的現(xiàn)象!當(dāng)遇到這種情況時(shí),可以看看是下面這篇文章,再按照方法來解決!2016-09-09
Android實(shí)現(xiàn)獲取簽名及公鑰的方法
這篇文章主要介紹了Android實(shí)現(xiàn)獲取簽名及公鑰的方法,可實(shí)現(xiàn)Android通過包名獲取相關(guān)簽名及公鑰的功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android ListView實(shí)現(xiàn)下拉頂部圖片變大效果
這篇文章主要為大家詳細(xì)介紹了Android ListView實(shí)現(xiàn)下拉頂部圖片變大,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
viewPager+fragment刷新緩存fragment的方法
這篇文章主要介紹了viewPager+fragment刷新緩存fragment的方法,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03
Android提高之MediaPlayer播放網(wǎng)絡(luò)視頻的實(shí)現(xiàn)方法
這篇文章主要介紹了Android的MediaPlayer播放網(wǎng)絡(luò)視頻的實(shí)現(xiàn)方法,是一個非常實(shí)用的功能,需要的朋友可以參考下2014-08-08
Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法,結(jié)合實(shí)例形式分析了Android編程針對快捷方式的常用操作技巧,需要的朋友可以參考下2017-02-02

