Android之Button

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>
<string name= "app_name" > MyTest160707 </string>
<string name= "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>
<color name= "colorPrimary" > #3F51B5 </color>
<color name= "colorPrimaryDark" > #303F9F </color>
<color name= "colorAccent" > #FF4081 </color>
</resources>
调用
android :background= "@color/colorPrimary"
在Text中可以看到Button的参数设置,可以更改 android : text的值修改Button中的显示字符
2.也可以在strings.xml文件中添加资源信息
<resources>
<string name= "app_name" > MyTest160707 </string>
<string name= "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>
<color name= "colorPrimary" > #3F51B5 </color>
<color name= "colorPrimaryDark" > #303F9F </color>
<color name= "colorAccent" > #FF4081 </color>
</resources>
调用
android :background= "@color/colorPrimary"
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值