标签: materialbutton

文本顶部带有图标的 Android 材质按钮

是否可以在其文本顶部有一个带有图标的材质按钮:

纽扣

如果是的话,你能用一些代码解释一下吗?

谢谢你。

android android-button kotlin material-components-android materialbutton

5
推荐指数
1
解决办法
1674
查看次数

更改MaterialButtonToggleGroup的背景颜色

我正在使用 MaterialButtonToggleGroup 创建选择器按钮。我想更改 MaterialButton 按钮的背景颜色。它的默认颜色是浅蓝色,我想将其更改为浅绿色。目前,我正在使用可绘制扇区来更改背景颜色,但它不起作用。

默认颜色在此输入图像描述

想要这个颜色, 在此输入图像描述

这是我的布局,

<com.google.android.material.button.MaterialButtonToggleGroup
    android:id="@+id/toggleContent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:checkedButton="@id/btnOutline"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    android:visibility="visible"
    app:layout_constraintRight_toRightOf="parent"
    app:singleSelection="true">

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnOutline"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:text="@string/outline"
        android:textAllCaps="false" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnMain"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:background="@drawable/button_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/main"
        android:textAllCaps="false" />

</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)

这是我的可绘制文件“button_selector”,

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true" android:drawable="@drawable/selector_color"/>

</selector>
Run Code Online (Sandbox Code Playgroud)

这是“selector_color”文件,

  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <solid android:color="#93cdcb"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

android android-togglebutton material-design materialbutton

5
推荐指数
1
解决办法
5374
查看次数

如何在材质按钮上编写多行文本?

我需要制作一个多行文本材质按钮。我遵循了这个问题的答案,但事实证明材质按钮的工作方式不同。

<com.google.android.material.button.MaterialButtonToggleGroup
    android:id="@+id/toggle_parent_child"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:theme="@style/Theme.MaterialComponents"
    android:visibility="gone"
    app:checkedButton="@id/button_parent"
    app:singleSelection="true">

    <com.google.android.material.button.MaterialButton
        android:id="@+id/button_parent"
        style="@style/Login.Button.ToggleButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Parent\n Device" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/button_child"
        style="@style/Login.Button.ToggleButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Child \n Device" />
Run Code Online (Sandbox Code Playgroud)

我得到这个:

图像

但我需要每个单词都在不同的行中,如下所示:

图像

xml user-interface android materialbutton

4
推荐指数
1
解决办法
2716
查看次数

更新到材质 1.2.0 后,材质按钮上缺少圆角半径属性

这是我的材质按钮代码:

<com.google.android.material.button.MaterialButton
    android:id="@+id/next_button"
    android:layout_width="224dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="68dp"
    android:layout_marginTop="510dp"
    android:layout_marginEnd="68dp"
    android:layout_marginBottom="68dp"
    android:background="@color/colorPrimary"
    android:minHeight="60dp"
    android:text="@string/onboarding_next_button"
    android:textColor="@android:color/white"
    app:cornerRadius="25dp" />
Run Code Online (Sandbox Code Playgroud)

将材质库从 1.1.0 更新到 1.2.0 后,app:CornerRadius 将被忽略。我尝试使用形状主题遵循材质文档,但控件仍然完全方形

android android-button material-design material-components-android materialbutton

3
推荐指数
1
解决办法
1634
查看次数