简体   繁体   English

要聚焦的按钮和默认选择的条件

[英]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. 另外,目前,由于android:background =“ @ drawable / buttons”是图像,因此按钮未聚焦。

Kindly provide your inputs/sample code/xml to solve the issue. 请提供您的输入信息/示例代码/ xml以解决该问题。

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. 一个简单的解决方案是使用ImageButtons并将您的drawable设置为src属性。 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 请在此类似的帖子中查看: 删除EditText的焦点边框

There I already explained this scenario. 在那里,我已经解释了这种情况。

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

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