国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android自定義view實(shí)現(xiàn)輸入框效果

瀏覽:6日期:2022-09-20 16:13:41

本文實(shí)例為大家分享了Android自定義view實(shí)現(xiàn)輸入框的具體代碼,供大家參考,具體內(nèi)容如下

自定義輸入框的View

package com.fenghongzhang.day017;import android.content.Context;import android.content.res.TypedArray;import android.text.InputType;import android.util.AttributeSet;import android.view.LayoutInflater;import android.view.View;import android.widget.EditText;import android.widget.ImageView;import android.widget.LinearLayout;import androidx.annotation.NonNull;import androidx.annotation.Nullable;public class InputView extends LinearLayout { private int inputview_input_icon; private String inputview_input_hint; private boolean inputview_is_pass; private View inflate; ImageView imageView; EditText editText; public InputView(@NonNull Context context) { super(context); } public InputView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(context,attrs); } public void init(Context context,AttributeSet attr){ if(attr==null){ return; } TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.InputView); inputview_input_icon = typedArray.getResourceId(R.styleable.InputView_input_icon, R.mipmap.ic_launcher); inputview_input_hint = typedArray.getString(R.styleable.InputView_input_hint); inputview_is_pass = typedArray.getBoolean(R.styleable.InputView_is_pass, false); //釋放資源 typedArray.recycle(); //加載. inflate = LayoutInflater.from(context).inflate(R.layout.inputview, this, false); imageView= (ImageView)inflate.findViewById(R.id.icon); editText= (EditText)inflate.findViewById(R.id.text);imageView.setImageResource(inputview_input_icon); editText.setText(inputview_input_hint); //設(shè)置樣式,是不是密文格式,可以沒(méi)有. editText.setInputType(inputview_is_pass? InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD:InputType.TYPE_CLASS_PHONE);//添加到viewgroup中 addView(inflate); } //用來(lái)取到輸入框的值. public String getString(){ return editText.getText().toString().trim(); }}

輸入框的布局

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='300dp' android:orientation='horizontal' android:layout_height='50dp' android:background='@drawable/back_color' android:layout_gravity='center_vertical' > <ImageView android:layout_width='wrap_content' android:layout_height='wrap_content' android:src='http://m.cgvv.com.cn/bcjs/@mipmap/ic_launcher' android:layout_gravity='center_vertical' android: /> <EditText android:layout_marginLeft='30dp' android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_gravity='center_vertical' android:hint='username' android:textSize='30dp' android:background='@null' android: /></LinearLayout>

屬性文件

<?xml version='1.0' encoding='utf-8'?><resources> <declare-styleable name='InputView'> <!--圖片--> <attr name='input_icon' format='reference'></attr> <!--字體--> <attr name='input_hint' format='string'></attr> <!--是否密文--> <attr name='is_pass' format='boolean'></attr> </declare-styleable> </resources>

布局中引用

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:my='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.Main3Activity'> <com.fenghongzhang.day017.InputView android:layout_width='300dp' android:layout_height='50dp' my:input_icon='@mipmap/ic_launcher' my:input_hint='手機(jī)號(hào)' my:is_pass='true' > </com.fenghongzhang.day017.InputView></LinearLayout>

輸入框圓角背景

<?xml version='1.0' encoding='utf-8'?><shape xmlns:android='http://schemas.android.com/apk/res/android'> <corners android:radius='10dp' ></corners> <size android: android:height='30dp'></size> <solid android:color='@color/colorAccent'></solid></shape>

效果

Android自定義view實(shí)現(xiàn)輸入框效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 九九九热在线精品免费全部 | 成年人免费看视频 | 成人欧美日韩视频一区 | 亚洲国产精品免费观看 | 99国产精品久久久久久久成人热 | 色综合久久88色综合天天提莫 | www.黄.com| 深夜国产 | 午夜精品视频 | 男人的天堂高清在线观看 | 男人好大好硬好爽免费视频 | 欧美一区二区三区免费高 | 国产爽的冒白浆的视频高清 | 欧美黄区 | 思思久热re6这里有精品 | 久久国产精品二区99 | 日韩成人一级 | 国产成人免费网站 | 久久91精品国产91久久小草 | 国产成人精品高清免费 | 欧美日本在线视频 | 另类视频综合 | 欧美日韩在线播放一区二区三区 | 国产99久久九九精品免费 | 亚洲毛片在线播放 | 久久精品国产99国产精品亚洲 | 国产高清一区二区三区视频 | 欧洲亚洲一区二区三区 | 亚洲欧美日韩中文字幕在线 | 成人在线午夜 | 国产日韩精品欧美一区视频 | ririai99在线视频观看 | 欧美成人性动漫在线观看 | 欧美久草视频 | 精品特级一级毛片免费观看 | 欧美日韩亚洲国内综合网俺 | 久久亚洲一级毛片 | 9久9久热精品视频在线观看 | 国产偷自拍 | 亚洲一区二区三区国产精品 | 久久99精品久久久久久国产越南 |