繁体   English   中英

可绘制的按钮选择器在触摸时不变

[英]Button selector drawable not changing on touch

我已经制作了一个包含3种状态的按钮选择器-默认,已聚焦和已启用/已激活。 我的意图ID默认情况下显示@drawable/normal @drawable/focused当触摸/按下; @drawable/enabled按钮启用后。 但它不起作用,并且仅显示默认(正常)可绘制。

drawable-hdpi / button_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/enabled" android:state_pressed="true"></item>
    <item android:drawable="@drawable/focused" android:state_focused="true"></item>
    <item android:drawable="@drawable/normal"></item> 

</selector>

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/AppBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".RitualMainActivity" >

    <include layout="@layout/merge_separator" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/button_selector" />

</LinearLayout>

使用ImageButton代替imageview.Imageview默认情况下不可点击,请参阅选择器不适用于布局和图像视图

尝试....通过添加clickable属性..您可以解决问题

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/button_selector" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM