[英]Make my LinearLayout act like a button
I have a linear layout with custome views inside it and would like them to act like a button, so highlight itself when it is pressed. 我有一个线性布局,里面有自定义视图,并希望它们像按钮一样,因此在按下时突出显示。
I looked into Drawable resources but cant quite understand how it is done. 我查看了Drawable资源,但不太明白它是如何完成的。
Any ideas? 有任何想法吗?
Create selector.xml
file in res/drawable/
folder 在res/drawable/
文件夹中创建selector.xml
文件
add next code: 添加下一个代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/YOUR_CUSTOM_VIEW_PRESSED_BACKGROUND" android:state_pressed="true" />
<item android:drawable="@drawable/YOUR_CUSTOM_VIEW_NORMAL_BACKGROUND" />
</selector>
In your custom view add android:background="@drawable/selector"
在您的自定义视图中添加android:background="@drawable/selector"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.