【问题标题】:Button to be focussed & in default selected condition按钮被聚焦并处于默认选中状态
【发布时间】:2011-04-06 19:16:52
【问题描述】:

我正在显示移动应用程序的条款和条件屏幕作为第一个屏幕。

我正在使用布局文件来显示屏幕。

在布局文件中,我有两个按钮,一个用于接受,一个用于拒绝

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

默认要求是,拒绝按钮应处于选中状态。此外,目前,由于 android:background="@drawable/buttons" 是图像,因此按钮没有获得焦点。

请提供您的输入/示例代码/xml 以解决问题。

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    问题在于按钮上的焦点指示器只不过是背景图像。因此,当您使用可绘制对象设置背景时,您将禁止系统在按钮更改其状态时使用聚焦的背景图像。

    一个简单的解决方案是使用ImageButtons 并将您的drawable 设置为src 属性。然后你有一个按钮,你的图像在中心。底层背景可以更改为默认的焦点背景图像。如果您不想要图像下方的灰色区域并且仍想使用按钮,则必须根据按钮的状态定义自定义样式。请查看此类似帖子:Remove focus border of EditText

    我已经解释了这种情况。

    【讨论】:

      猜你喜欢
      • 2022-11-16
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      相关资源
      最近更新 更多