360安全卫士

夏青青
2023-12-01
走马灯
1.在布局文件中设置一个特定五个属性
2.摆放多个走马灯,需要自定义控件
3.自定义控件需要先创建一个包,取名一个类继承TextView:复写两个构造函数:一个带一个参数的,一个带2个构造函数的
4.在第二个构造函数中设置五个属性,写一个方法,inFocused(),返回true
5.获取焦点一个是窗体内部一个是窗体外部的方法
==================================================================
设置按钮的背景
1.在res/新建一个drawable文件/建一个setting.xml文件/选择一个图形Shape,在这个节点里面设置其布局,大小,形状,等
指定类型:android:shape="ovl";设置大小.size:宽高, 设置半径corners.radius=16dp;设置背景 solid
2然后再布局中引用setting,xml文件 引用<ImageView android:background="@drawable/setting_shape">
  android;scaleType="center"缩放背景
3创建状态选择器:在在res/新建一个drawable文件/建两个seetng_selector.xml文件/选择一个图形selector在这个节点里面设置两种状态
  一种是嗯压状态,一种是其他状态
4.回到布局中引用seetng_selector.xml<ImageView android:background="@drawable/setting_selector>
====================================================
布局<GridView>
1.写布局,高宽,id,numColums=2显示的列数 设置水平间距:horizontalspacing="2dp":设置垂直间距:verticalaSpacing="2dp"
2,在java代码中,找到GridView的id,设置适配器继承BaseAdapter();实现里面的方法
3.创建一个包,写一个Javabean类
4.在res写一个item的布局,写布局
5.在java写代码
6.设置状态选择器
================================================
设置中心:
1.新建一个SettingActivity,继承activity,实现方法
2.创建布局,写布局
3.在res/values/写一个有关颜色的xml文件<resources>节点里<color name="title_bg">颜色<color>
4.回到布局中可以把背景颜色改为 background="@color/title_bg"
5.在SettingActivity 设置布局,界面跳转
6.把资源图片放在res/drawablehdpi中
7,写条目布局
8.创建背景,在res/新建一个drawable文件 创建状态选择器 ,创建3个有上中下
9,在布局中引用 clickable=true.可以点击条目
==================================================
组合式自定义控件和自定义属性(把多个控件当做一个控件)
1,新建一个布局settingitemview.xml,将多个控件组合在一起
2,新建一个类继承这个布局的根部布局   settingitemview extends RelativeLayout
 实现里面的构造方法
3.需要将类和布局进行挂载 view.inflate(context.R.layout.view_setting_item,this);
4在布局中使用,复制类名的全包名+类名,回到布局中如:
<com.heima.safe.activity.SplashActivity
   android:layout_width="wrap_content"
        android:layout_height="wrap_content"
>
5.自定义属性
5.1:在values 文件夹下新建一个attrs.xml文件,在<resources>节点里
 自定义属性<declare_styleable name="settingitemview"> 这个name是布局的名称
  文本显示<attr name="sivText" format="string/reference">  format:指文本类型 name:指属性值.不能写TEXT,要和系统区分
5.2.新建属性
5.3.使用属性:回到布局中节点中,要声明命名空间在布局跟节点下
xmlns:itheima="http://schemas.android.com/apk/res/ com.itheima.zphuanlove(包名)
如属性的:使用时:itheima:sivText="自动更新"
5.4.在代码中接收属性,设置属性
接收属性:TypedArray ta = context.obtainStyledAttributes(attrs,
                R.styleable.SettingItemView);
 获取文本属性值: String text = ta.getString(R.styleable.SettingItemView_sivText);
5.5.背景解决方案.枚举,在属性中设值布局,如: <!-- 自定义背面 -->
        <attr name="sivBackground">
            <enum name="start" value="0" />
            <enum name="middle" value="1" />
            <enum name="end" value="2" />
        </attr>
5.6:回到布局中设置 itheima:sivBackground="start"
                  itheima:sivBackground="middle"
                itheima:sivBackground="end"
5.7在代码中接收属性,设置背景看代码20
5.8.设置开关   <!-- 是否有开关 -->
        <attr name="sivToggleEnable" format="boolean" />
 类似资料: