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游戲開發(fā)學(xué)習(xí)②焰火綻放效果實(shí)現(xiàn)方法
這篇文章主要介紹了Android游戲開發(fā)學(xué)習(xí)②焰火綻放效果實(shí)現(xiàn)方法,以實(shí)例形式詳細(xì)分析了Android中粒子對象類Particle類和粒子集合類ParticleSet類及物理引擎ParticleThread類 的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10android實(shí)現(xiàn)文本復(fù)制到剪切板功能(ClipboardManager)
Android也有剪切板(ClipboardManager),可以復(fù)制一些有用的文本到剪貼板,以便用戶可以粘貼的地方使用,下面是使用方法2014-02-02Android中AlertDialog用法實(shí)例分析
這篇文章主要介紹了Android中AlertDialog用法,結(jié)合實(shí)例形式簡單分析了AlertDialog的基本調(diào)用與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01Android自定義View構(gòu)造函數(shù)詳解
這篇文章主要為大家詳細(xì)介紹了Android自定義View構(gòu)造函數(shù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android在線更新SDK的方法(使用國內(nèi)鏡像)
這篇文章主要介紹了Android在線更新SDK的方法,分別介紹了修改hosts文件使用谷歌官方鏡像更新及使用國內(nèi)鏡像更新SDK的方法,非常簡單實(shí)用,需要的朋友可以參考下2015-12-12Android Button的基本用法詳解及簡單實(shí)例
這篇文章主要介紹了Android Button的基本用法詳解及簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-02-02