[英]Android: onClick on LinearLayout with TextView and Button
[英]TextColor of button is not changing onclick of parent LinearLayout
当我单击其父级线性布局时,我想更改按钮的文本颜色并修改图像。 单击线性布局时,图像正在更改,但textcolor并未更改。
这是我在xml中的代码 -
<LinearLayout
android:id="@+id/btn_layout"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.0"
android:gravity="center"
android:clickable="true"
android:orientation="horizontal" >
<Button
android:id="@+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/done_with_accounts_action"
android:textColor="@drawable/done_button_text_selector"
android:focusable="false"
android:textSize="@dimen/done_button_text_size" />
<ImageView
android:id="@+id/done_btn_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:focusable="false"
android:src="@drawable/done_btn_arrow_bg_selector" />
</LinearLayout>
**selector xml for button -**
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/done_btn_pressed_color" />
<item android:state_pressed="true" android:color="@color/done_btn_pressed_color" />
<item android:color="@color/button_text_white_color" />
</selector>
如果我用TextView替换按钮,一切正常。
在这行中:
<item android:state_focused="true" android:color="@color/done_btn_pressed_color" />
<item android:state_pressed="true" android:color="@color/done_btn_pressed_color" />
您输入了相同的颜色done_btn_pressed_color
。 也许那是问题所在?
我找到了解决方案-我必须将完成按钮设置为clickable,现在它也可以识别其父onClick事件。
为何上面的代码与textView一起使用,因为默认情况下禁用了它的onClick事件,因此它可以识别其父onClick事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.