簡體   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