Android布局之LinearLayout自定義高亮背景的方法
本文實(shí)例講述了Android布局之LinearLayout自定義高亮背景的方法。分享給大家供大家參考,具體如下:
首先創(chuàng)建linearlayout_background.xml文件
res/drawable/linearlayout_background.xml
<?xml version="1.0" encoding="utf-8"?> <selectorxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:state_pressed="true" android:drawable="@drawable/button_pressed"/> <itemandroid:state_focused="true" android:drawable="@drawable/button_pressed"/> <itemandroid:drawable="@drawable/button_normal"/> </selector>
其次在對(duì)應(yīng)的xml布局文件中
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:clickable="true"<!--這條是必須的,否則沒(méi)有高亮顯示效果,這有別于自動(dòng)的button,textview等其他控件--> android:background="@drawable/linearlayout_background"> <Button ....../> <TextView ...../> </LinearLayout>
更多關(guān)于Android布局相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android使用IntentService進(jìn)行apk更新示例代碼
這篇文章主要介紹了Android使用IntentService進(jìn)行apk更新示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01android實(shí)現(xiàn)上下左右滑動(dòng)界面布局
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)上下左右滑動(dòng)的界面布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12Android 使用ViewPager自動(dòng)滾動(dòng)循環(huán)輪播效果
本文主要給大家介紹viewpager自動(dòng)播放,循環(huán)滾動(dòng)的效果,對(duì)android viewpager滾動(dòng)相關(guān)知識(shí)感興趣的朋友可以參考下本篇文章2015-11-11Android提高之ListView實(shí)現(xiàn)自適應(yīng)表格的方法
這篇文章主要介紹了Android采用ListView實(shí)現(xiàn)自適應(yīng)表格的方法,比較實(shí)用的功能,需要的朋友可以參考下2014-08-08Android開發(fā)之高德地圖實(shí)現(xiàn)定位
本篇文章主要介紹了Android中高德地圖實(shí)現(xiàn)定位的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04Android Studio下的APP目錄結(jié)構(gòu)詳解
這篇文章主要介紹了AndroidStudio下的APP目錄結(jié)構(gòu),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05