安卓第二天2020-11-25

这篇博客详细梳理了2020年11月25日在B站学习安卓开发的心得,主要围绕Button和EditText展开,包括Button的文字设置、自定义背景和按压效果,以及两种点击事件的实现方法;EditText的常用属性和监听事件。同时探讨了在MainActivity中提高代码复用的策略以及RadioButton的属性定制和监听事件。
摘要由CSDN通过智能技术生成

安卓b站学习笔记梳理2020.11.25

天哥在奔跑安卓教程b站网址https://www.bilibili.com/video/BV1Rt411e76

目录

安卓b站学习笔记梳理2020.11.25

4.Button

①文字大小、颜色

②自定义背景形状

③自定义按压效果

④点击事件第一种方法

⑤点击事件第二种方法

5.EditText

①常用属性(以用户名输入框为例)

②监听事件

6.0MainActivity中提高代码复用的做法

7.RadioButton

①常用属性(创建RadioGroup并且在下面新建RadioButton)

②自定义样式(取消圆圈并且实现点击有其他样式)xml如下

③监听事件



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"
    />

②自定义背景形状

  1. 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>
  2. 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>
  3. 然后在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>

④点击事件第一种方法

点击事件几乎适用于所有组件

  1. BUTTON中添加
    android:onClick="showToast"
  2. 在ButtonAcitivity中加入
    public void showToast(View view)
    {
        Toast.makeText(this,"Button4 is clic
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值