</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>