This article describes the method of LinearLayout custom highlighting background in Android layout. Share it for your reference, as follows:
First create the linearlayout_background.xml file
res/drawable/linearlayout_background.xml
<?xml version="1.0" encoding="utf-8"?> <selectorxmlns:andro> <itemandroid:state_pressed="true" android:drawable="@drawable/button_pressed"/> <itemandroid:state_focused="true" android:drawable="@drawable/button_pressed"/> <itemandroid:drawable="@drawable/button_normal"/> </selector>
Secondly, 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 is no highlighting effect,This is different from automaticbutton,textviewOther controls--> android:background="@drawable/linearlayout_background"> <Button ....../> <TextView ...../> </LinearLayout>
For more information about Android layout, readers who are interested in view the topic of this site:Android layout layout tips summary》
I hope this article will be helpful to everyone's Android programming design.