久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

Android自定義view實現輸入框效果

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

本文實例為大家分享了Android自定義view實現輸入框的具體代碼,供大家參考,具體內容如下

自定義輸入框的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); //設置樣式,是不是密文格式,可以沒有. editText.setInputType(inputview_is_pass? InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD:InputType.TYPE_CLASS_PHONE);//添加到viewgroup中 addView(inflate); } //用來取到輸入框的值. 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://www.gepszalag.com/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='手機號' 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實現輸入框效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: a级毛片免费高清视频 | 日韩午夜av| 日日夜夜天天干干 | 九九色综合| 午夜精品久久久久久久男人的天堂 | 伊人网影院 | 日韩在线观看中文字幕 | 国产精品久久久久久久久久妞妞 | 欧洲亚洲精品久久久久 | 综合久久99 | 成人水多啪啪片 | 国产精品久久精品 | 中国91视频 | 欧美日韩福利 | 九九在线国产视频 | 久久成人一区二区 | 精品国产天堂 | 一区二区三区在线观看视频 | 色小妹三区| 视频一区 中文字幕 | 国产一区二精品区在线 | 国产在线精品一区 | 羞羞av在线| 成人av电影网址 | 亚洲精品66 | 欧美日韩国产在线看 | 黄毛片网站 | 91在线激情 | 亚洲97视频 | 精品成人佐山爱一区二区 | 欧美成人精品一区二区男人看 | 嫩草私人影院 | 亚洲人人 | 日本不卡在线 | 国产一区二区三区精品久久久 | 免费看91 | 欧美日韩国产一区二区三区 | 视频一区二区三区在线观看 | 亚洲精品电影 | 国产成人网 | 极品女神高潮呻吟av久久 |