LinearLayout custom highlighting method for Android layout
- 2021-01-18 06:37:33
- OfStack
This article illustrates the LinearLayout approach to custom highlighting of Android layouts. To share with you for your reference, as follows:
First create the file 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>
The second is in the corresponding xml layout file
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="true"<!-- This is a must, otherwise there will be no highlighting, which is different from automatic button . textview And other controls. -->
android:background="@drawable/linearlayout_background">
<Button ....../>
<TextView ...../>
</LinearLayout>
For more information about Android layout, readers interested in Android layout can check out the special topic on this site: Summary of Android layout tips
Hope this article described to everyone Android program design is helpful.