android 基础笔记 (一)

主要记录一些基础组件的使用

1. selector

selector 用于解决 组件在不同状态下展示什么的问题

2. 组件阴影设置

android:shadowColor // 阴影颜色
android:shadowRadius // 阴影半径 从视觉效果上 值越大 阴影看起来越模糊 (3.0看起来还行)
android:shadowDx // 阴影相对于原文 在x轴偏移
android:shadowDy // y轴偏移

实际配置

  android:shadowColor="@color/purple_200"
        android:shadowRadius="3.0"
        android:shadowDx="-30"
        android:shadowDy="20"

效果
天生我材必有用

3. Button 背景颜色设置

android:background # 可设置 按下和非按下时展示的图案
android:backgroundTint # 可设置按下和非按下时展示的颜色
 android:backgroundTint="@color/btn_color"
 android:background="@drawable/btn_presess_draw"

未按下时
在这里插入图片描述
按下时
按下时
如果发现背景颜色设置不管用:

关于Android中Button的Backgroud背景设置默认为蓝紫色,且无法修改的问题

4. 进度条

    <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"  # 水平展示
        android:layout_width="200dp"
        android:layout_height="15dp"
        android:max="100" # 进度条最大值
        android:progress="20" #设置初始值
        android:visibility="visible" 
        />

进度条
如果设置 indeterminate 为 true (不展示进度)

在这里插入图片描述

5. Dialog

  new AlertDialog.Builder(getContext())
                .setTitle("将进酒作者?")
                .setIcon(R.drawable.ic_baseline_tag_faces_24)
                .setPositiveButton("李白", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //
                    }
                })
                .setNegativeButton("杜甫", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //
                    }
                })
                .create().show();

效果

Dialog

6. 弹窗底部展示

效果
底部弹窗

View popupView = getLayoutInflater().inflate(R.layout.popup_test, null);
        PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.showAtLocation(root, Gravity.BOTTOM, 0, 0); // 控制底部展示

popup_test - xml

<?xml version="1.0" encoding="utf-8"?>
<android.widget.LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:text="发送通知"
        android:background="@color/purple_200"
        android:backgroundTint="@color/purple_200"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="弹窗测试"
        android:background="@color/purple_200"
        android:backgroundTint="@color/purple_200"
        android:textSize="30sp"
        />

</android.widget.LinearLayout>

7. LinearLayout 设置分隔线

 android:divider="@drawable/ic_baseline_linear_scale_24"
 android:showDividers="middle"

效果

分隔线

8. ConstraintLayout 设置权重

垂直方向占据剩余空间

android:layout_height="0dp"

可以看到中间组件的大小刚好充满剩余空间
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值