日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android自定义华为睡眠,Android自定义View

發布時間:2023/12/18 Android 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android自定义华为睡眠,Android自定义View 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文章主要介紹Android系統中,自定義View的開發。

通常用于展示特定的樣式,或抽象控件,方便復用。

1.自定義控件的傳參

定義declare-styleable,方便從XML布局文件中傳入類內部。

文件目錄:

res\values\atts.xml

文件內容:

2.自定義類

以EditText為例,展示獲取XML中設置的變量

package com.lizheblogs.view;

import android.content.Context;

import android.content.res.Resources;

import android.content.res.TypedArray;

import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatEditText;

import com.teenysoft.jdxs.R;

public class SupEditText extends AppCompatEditText {

private boolean isFilters = true;

private float emptyTextSize = 12;

private float textSize = 14;

private int errorHintColor;

private float errorTextSize = 14;

private String errorText1;

private String errorText2;

public SupEditText(Context context) {

super(context);

init(context, null);

}

public SupEditText(Context context, AttributeSet attrs) {

super(context, attrs);

init(context, attrs);

}

public SupEditText(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

init(context, attrs);

}

private void init(Context context, AttributeSet attrs) {

Resources resources = context.getResources();

errorHintColor = resources.getColor(R.color.edit_text_error_text);

if (attrs != null) {

//從xml的屬性中獲取到字體顏色與string

TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SupEditText);

isFilters = ta.getBoolean(R.styleable.SupEditText_isFilters, true);

emptyTextSize = ta.getDimension(R.styleable.SupEditText_emptyTextSize, 12);

textSize = ta.getDimension(R.styleable.SupEditText_textSize, 14);

errorHintColor = ta.getColor(R.styleable.SupEditText_errorHintColor,

errorHintColor);

errorTextSize = ta.getDimension(R.styleable.SupEditText_errorTextSize, 14);

errorText1 = ta.getString(R.styleable.SupEditText_errorText1);

errorText2 = ta.getString(R.styleable.SupEditText_errorText2);

ta.recycle();

}

}

}

這樣就可以通過XML中的設置,來改變控件的樣式。

3.XML布局

在XML布局中設置變量的值。

以EditText為例,展示XML中設置變量

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:ts="http://schemas.android.com/apk/res-auto"

android:id="@+id/userNameET"

android:layout_width="match_parent"

android:layout_height="match_parent"

ts:emptyTextSize="12sp"

ts:errorHintColor="@color/edit_text_error_text"

ts:errorText1="@string/input_user_name_please"

ts:errorTextSize="14sp"

ts:isFilters="true"

ts:textSize="14sp" />

ts為空間名,可隨意。

大功告成!

總結

以上是生活随笔為你收集整理的Android自定义华为睡眠,Android自定义View的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。