繁体   English   中英

为什么在Android中按下背景按钮时没有焦点?

[英]Why Button with Background gets no focus when pressed in android?

这是一个带有背景的按钮,触摸该按钮时不会聚焦。 这是xml:

<Button
        android:id="@+id/continueID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:background="@drawable/buttonbg"
        android:focusableInTouchMode="true"
        android:focusable="true" 
        android:onClick="invokeLogin"
        android:text="Login"
        android:textColor="#F7F9FA" />

“ buttonbg”背景必须处理焦点状态,以便您触摸时可以看到更改。

例如:-

// buttonbg.xml 

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@drawable/your_imagename_while_focused"/>
    <item android:state_pressed="true" android:drawable="@drawable/your_imagename_while_pressed" />
    <item android:drawable="@drawable/image_name_while_notpressed" />  //means normal
</selector>

暂无
暂无

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

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