【发布时间】:2019-05-26 08:10:25
【问题描述】:
我正在创建一个清单,我有 2 个按钮。当我单击 false 时,我想更改样式。当我点击真时,我希望假恢复原来的风格,并改变真按钮的风格
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/inspectionItemText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="2"
android:text="Inspection Item"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/itemInspectedTrue"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@drawable/button_border"
android:text="Pass"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold" />
<Button
android:id="@+id/itemInspectedFalse"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@drawable/button_border"
android:text="Fail"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold" />
</LinearLayout>
【问题讨论】:
-
你可以使用选择器。
-
您可以在布局中动态添加按钮并更改样式属性
标签: android android-layout kotlin android-button