安卓b站学习笔记梳理2020.11.25
天哥在奔跑安卓教程b站网址https://www.bilibili.com/video/BV1Rt411e76
目录
①常用属性(创建RadioGroup并且在下面新建RadioButton)
4.Button
①文字大小、颜色
<Button
android:id="@+id/btn_2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Button2"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:background="@drawable/bg_btn2"
android:layout_below="@id/btn_1"
android:layout_marginTop="10dp"
/>
②自定义背景形状
- drawable->new drawable resources file->shape(Root element)-------(实心背景颜色+圆角)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FF9900"/> <corners android:radius="15dp"/> </shape>
- drawable->new drawable resources file->shape(Root element)-------(空心背景颜色+圆角)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke android:width="3dp" android:color="#FF9900"/> <corners android:radius="15dp"/> </shape>
- 然后在button中的 android:background后面赋值"@drawable/bg_btn2",就可以实现绑定
③自定义按压效果
drawable->new drawable resources file->selector(Root element)-------(按压效果)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#AA6600"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape>
<solid android:color="#FF9900"/>
<corners android:radius="5dp"/>
</shape>
</item>
</selector>
④点击事件第一种方法
点击事件几乎适用于所有组件
-
BUTTON中添加 android:onClick="showToast"
- 在ButtonAcitivity中加入
public void showToast(View view) { Toast.makeText(this,"Button4 is clic