简体   繁体   中英

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

Here is a button with background that gets no focus when touch it. Here is the 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' background must handle the focused state so you can see changes when you touch it.

For example:-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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