linearLayout等布局添加动态背景(运用xml)注意加上clickable
发布时间:2020-12-16 09:44:25 所属栏目:百科 来源:网络整理
导读:/preppre name="code" class="html" 博主这些天在写一个app社交软件,开发过程中奇葩问题也是各种乱入,这个也算是其中之一,主要以前不用layout布局做按钮类,所以也不会做它的背景。话不多说,上代码: 这是布局文件: pre name="code" class="html"Linear
</pre><p><pre name="code" class="html"> 博主这些天在写一个app社交软件,开发过程中奇葩问题也是各种乱入,这个也算是其中之一,主要以前不用layout布局做按钮类,所以也不会做它的背景。话不多说,上代码: 这是布局文件: <pre name="code" class="html"><LinearLayout android:id="@+id/ll_photo_local_get" android:layout_width="200dp" android:layout_height="wrap_content" android:background="@drawable/tv2_selector" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="现在拍摄" android:textColor="@color/deepgrey" android:textSize="18sp" /> </LinearLayout> 这是tv1_selector选择器: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="false" android:state_focused="false" android:drawable="@color/white"></item> <item android:state_focused="true" android:drawable="@color/lightgray"></item> <item android:state_pressed="true" android:drawable="@color/lightgray"></item> </selector> 然后怎么也出不来这个效果:
本来感觉根本不会出问题的,后来在网上查了才知道layout都有一个clickable属性,否则点击是无效的 更改布局文件: <LinearLayout android:id="@+id/ll_photo_local_get" android:layout_width="200dp" android:layout_height="wrap_content" android:clickable="true" //这里为新增 android:background="@drawable/tv2_selector" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="现在拍摄" android:textColor="@color/deepgrey" android:textSize="18sp" /> </LinearLayout>这样就有该有的效果了。希望能帮助一些还会碰上这个问题的人吧!~ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |