开发工具:Andriod Studio 20203.1.25版本
操作系统:windws10
已经按照学习视频,添加依赖,修改app主题
学习MaterialButton组件,在layout(布局文件)编辑代码,其编辑的代码如下所示
问题:
运行结果与视频上的不一样,以下代码没有发挥它们的作用:
描边:app:strokeColor="#ff0000" app:strokeWidth="3dp"
星星图标:app:icon="@android:drawable/star_on"
图标着色:app:iconTint="#ff0000"
圆角:app:cornerRadius="30dp"
完整代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- xmlns:app="http://schemas.android.com/apk/res-auto"
为app提供命名空间,可以关键字出发提示;输入app,选择appNS-->
<com.google.android.material.button.MaterialButton
android:backgroundTint="@color/purple_200"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="圆角"
android:textSize="18dp"
android:textColor="#ff0000"
app:cornerRadius="10dp" />
<com.google.android.material.button.MaterialButton
android:layout_width="150dp"
android:layout_height="50dp"
android:text="圆角描边"
android:textSize="18dp"
android:textColor="@color/purple_200"
app:strokeColor="#ff0000"
app:strokeWidth="3dp"
app:cornerRadius="30dp" />
<com.google.android.material.button.MaterialButton
android:layout_width="150dp"
android:layout_height="50dp"
android:text="圆角描边"
android:textSize="18dp"
android:textColor="@color/teal_200"
app:icon="@android:drawable/star_on"
app:iconTint="#ff0000"
app:strokeColor="#ff0000"
app:strokeWidth="3dp"
app:cornerRadius="30dp"
/>
<Button
android:layout_width="150dp"
android:layout_height="60dp"
/>
</LinearLayout>