Android之Button

来源:互联网 发布:小说下载软件 编辑:程序博客网 时间:2024/06/15 13:45
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"
1 0
原创粉丝点击