具有 ButtonBarButtonStyle 的按钮不会在触摸时突出显示
Buttons with ButtonBarButtonStyle do not highlight on touch
有很多关于如何让按钮像标准对话按钮一样显示的解释 - 我遵循这些解释。我的 xml:
里有这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="?android:attr/dividerVertical"
style="?android:attr/buttonBarStyle"
android:showDividers="middle"
android:measureWithLargestChild="true">
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:background="@drawable/dialog_button"
android:text="@string/button_cancel" />
<Button
android:id="@+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
style="?android:attr/buttonBarButtonStyle"
android:background="@drawable/dialog_button"
android:text="@string/button_ok" />
</LinearLayout>
这非常有效,可以生成我需要的视觉设计。但是,当我触摸按钮时,它们不会突出显示。这很烦人,因为其他一切都应该如此。 buttonBarButtonStyle
似乎不包含按钮不同状态的状态可绘制对象。有什么简单的方法可以恢复高亮吗?
当然,我可以只定义自己的 state drawable 定义不同的颜色,但我想改用主题颜色。
您需要应用背景:
android:background="?android:attr/selectableItemBackground"
实现默认的 "button bar" 样式和行为。
有很多关于如何让按钮像标准对话按钮一样显示的解释 - 我遵循这些解释。我的 xml:
里有这个<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="?android:attr/dividerVertical"
style="?android:attr/buttonBarStyle"
android:showDividers="middle"
android:measureWithLargestChild="true">
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:background="@drawable/dialog_button"
android:text="@string/button_cancel" />
<Button
android:id="@+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
style="?android:attr/buttonBarButtonStyle"
android:background="@drawable/dialog_button"
android:text="@string/button_ok" />
</LinearLayout>
这非常有效,可以生成我需要的视觉设计。但是,当我触摸按钮时,它们不会突出显示。这很烦人,因为其他一切都应该如此。 buttonBarButtonStyle
似乎不包含按钮不同状态的状态可绘制对象。有什么简单的方法可以恢复高亮吗?
当然,我可以只定义自己的 state drawable 定义不同的颜色,但我想改用主题颜色。
您需要应用背景:
android:background="?android:attr/selectableItemBackground"
实现默认的 "button bar" 样式和行为。