1.新建android项目,打开activity_main.xml文件,选择下方Design,如果选中Button,在右侧android设备中添加Button
在Text中可以看到Button的参数设置,可以更改android:text的值修改Button中的显示字符
<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView" android:layout_marginTop="40dp" android:layout_toEndOf="@+id/textView" android:text="@string/btn_text" android:background="@color/colorPrimary"/>
2.也可以在strings.xml文件中添加资源信息
<resources>
<stringname="app_name">MyTest160707</string>
<stringname="btn_text">倔强的赞叹2</string>
</resources>
然后将android:text的值更改为btn_text的赋值
android:text="@string/btn_text"
这时显示的Button的字符就是“倔强的赞叹2”
3.同理可以在colors.xml文件中设置颜色属性,在activity_main.xml文件中使用
<?xml
version="1.0"encoding="utf-8"?>
<resources>
<colorname="colorPrimary">#3F51B5</color>
<colorname="colorPrimaryDark">#303F9F</color>
<colorname="colorAccent">#FF4081</color>
</resources>
调用
android:background="@color/colorPrimary"
在Text中可以看到Button的参数设置,可以更改android:text的值修改Button中的显示字符
2.也可以在strings.xml文件中添加资源信息
<resources>
<stringname="app_name">MyTest160707</string>
<stringname="btn_text">倔强的赞叹2</string>
</resources>
然后将android:text的值更改为btn_text的赋值
android:text="@string/btn_text"
这时显示的Button的字符就是“倔强的赞叹2”
3.同理可以在colors.xml文件中设置颜色属性,在activity_main.xml文件中使用
<?xml
version="1.0"encoding="utf-8"?>
<resources>
<colorname="colorPrimary">#3F51B5</color>
<colorname="colorPrimaryDark">#303F9F</color>
<colorname="colorAccent">#FF4081</color>
</resources>
调用
android:background="@color/colorPrimary"
本文介绍如何在Android项目中创建和定制Button组件,包括通过XML布局文件直接设置文本和颜色,以及利用strings.xml和colors.xml文件进行资源引用的方法。
361

被折叠的 条评论
为什么被折叠?



