简体   繁体   中英

Button to be focussed & in default selected condition

I am displaying a the Terms & Conditions screen of the mobile application as the first screen.

I am using a layout file to display the screen.

Within the layout file , I have two buttons , one for Accept & one for Reject

<Button android:id="@+id/acceptBtn" android:text="@string/accept"
            android:background="@drawable/buttons" android:textColor="@color/white"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

<Button android:id="@+id/rejecttBtn" android:text="@string/reject"
            android:background="@drawable/buttons" android:textColor="@color/white"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

The requirement by default is , the Reject button should be in selected condition. Also , currently , because of the android:background="@drawable/buttons" which is an image , the buttons are not getting focussed.

Kindly provide your inputs/sample code/xml to solve the issue.

Thanks in advance.

The problem is that the focus indicator on a button is nothing more than a background image. So when you set your background with a drawable you prohibit the system to use the focused background image when the button changes its state.

A simple solution is to use ImageButtons and to set your drawable as the src attribute. Then you have a button with your image in the center. The underlying background can change to the default focus background image. If you don't want the grey area underneath your image and still want to use buttons you would have to define customs styles depending on the state of the button. Please have a look in this similar post: Remove focus border of EditText

There I already explained this scenario.

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