Andorid复习

组件

TextView

阴影

复制代码
 android:shadowColor="@color/red" 阴影颜色
 android:shadowRadius="3.0" 阴影模糊度(大小)
 android:shadowDx="10.0" 横向偏移
 android:shadowDy="10.0" 

跑马灯

这里用自定义控件

复制代码
public class MyTextView extends TextView {
    public MyTextView(Context context) {
        super(context);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean isFocused() {
        return true;//获取聚焦
    }
}

 <com.example.derry.MyTextView
        android:id="@+id/tv_one"
        android:text="@string/tv_one"
        android:textColor="@color/black"
        android:layout_width="match_parent"
        android:textStyle="italic"
        android:textSize="30sp"
        android:gravity="center"
        android:layout_height="200dp"

        android:shadowColor="@color/red"
        android:shadowRadius="3.0"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        下面是跑马灯
        android:singleLine="true" //一条线显示不自动换行
        android:ellipsize="marquee" //
        android:marqueeRepeatLimit="marquee_forever" //循环次数
        android:focusable="true" //聚焦必写
        android:focusableInTouchMode="true"  //聚焦必写
        />

Button

stabteListDrawable

复制代码
设置button背景颜色时要改
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->

改下面这行
    <style name="Base.Theme.Derry" parent="Theme.MaterialComponents.DayNight.Bridge">
        <!-- Customize your light theme here. -->
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    </style>

    <style name="Theme.Derry" parent="Base.Theme.Derry" />
</resources>
条件选择器
按钮点击变换背景

在drawable中添加button规则

复制代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--    按下为-->
    <item android:drawable="@drawable/baseline_2k_plus_24" android:state_pressed="true"/>
<!--    不按为  默认为-->
    <item android:drawable="@drawable/ic_android_black_24dp"/>
</selector>

其中@drawable/为导入的xml图片 导入方式为

为页面的button绑定点击规则

复制代码
  <Button
        android:text="我是按钮"
        android:background="@drawable/btn_select" //规则
        android:textColor="@color/white"
        android:layout_width="200dp"
        android:layout_height="100dp"/>
点击变换背景色

EditText

配合button点击获取信息

复制代码
text设置的是全局 


Button btn = findViewById(R.id.btn_get);
        text = findViewById(R.id.text);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String te = text.getText().toString();
                Log.e("leo", "onClick:输入的内容是 "+te);
            }
        });

imageView

复制代码
    <ImageView
        android:src="@drawable/ceshi"
        android:maxWidth="200dp"
        android:maxHeight="200dp"
        android:adjustViewBounds="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

ProgressBar

点击不显示

复制代码
  public void leoClick(View view) {
        if (pb.getVisibility()==View.GONE)//不显示则显示
            pb.setVisibility(View.VISIBLE);//则显示
        else
            pb.setVisibility(View.GONE);///则隐藏
    }

点击进度条加长

复制代码
 public void load(View view) {
        int progress = load.getProgress();
        progress+=10;
        load.setProgress(progress);
    }

Notification消息通知

当android版本大于13时需要在这加上这句

复制代码
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

AlertDiaLog

复制代码
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="gaoClick"
        android:text="显示对话框"/>

自定义布局

相关推荐
lisw054 小时前
人和AI的分工模式!
人工智能·青少年编程
rengang664 小时前
002-Spring AI Alibaba Prompt 功能完整案例
人工智能·spring·prompt·spring ai·ai应用编程
Giser探索家4 小时前
无人机数字资产采集技术架构与实践:从多维度感知到云端化建模的实现路径
大数据·人工智能·算法·计算机视觉·分类·无人机
飞飞是甜咖啡4 小时前
读论文AI prompt
人工智能·prompt
GIS数据转换器4 小时前
基于GIS的智慧畜牧数据可视化监控平台
人工智能·安全·信息可视化·无人机·智慧城市·制造
千年奇葩5 小时前
Unity性能优化之:利用CUDA加速Unity实现大规模并行计算。从环境搭建到实战案例
c++·人工智能·unity·游戏引擎·cuda
攻城狮7号5 小时前
蚂蚁开源高性能扩散语言模型框架dInfe,推理速度提升十倍
人工智能·dinfer·扩散语言模型·蚂蚁开源模型
LONGZETECH5 小时前
【龙泽科技】汽车电子电气与空调舒适系统技术1+X仿真教学软件(1.3.2 -中级)【威朗&科鲁兹】
人工智能·科技·汽车·汽车仿真教学软件·汽车教学软件
机器之心5 小时前
为什么95%的智能体都部署失败了?这个圆桌讨论出了一些常见陷阱
人工智能·openai
AImatters5 小时前
AI照亮“星星的孩子”:大米和小米与亚马逊云科技探索特需儿童康复之路
人工智能·生成式ai·亚马逊云科技·大米和小米