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

歡迎訪問 生活随笔!

生活随笔

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

Android

edtext 从右边开始输入 安卓_Android开发之EditText属性详解

發布時間:2025/4/5 Android 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 edtext 从右边开始输入 安卓_Android开发之EditText属性详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、EditText輸入的文字為密碼形式的設置

(1)通過.xml里設置:

把該EditText設為:android:password="true"?// 以”.”形式顯示文本

(2)在代碼里設置:

通過設置EditText的setTransformationMethod()方法來實現隱藏密碼或這顯示密碼。

editText.setTransformationMethod(PasswordTransformationMethod.getInstance());//設置密碼為不可見。

2、(1)EditText輸入的文字為電話號碼

Android:phoneNumber=”true”??//輸入電話號碼

3、EditText字數限制的設置

(1)在.xml中設置:android:maxLength=“50”

(2)代碼中設置:

editText.setFilters(new InputFilter[]{newInputFilter.LengthFilter(100)});

4、EditText設置字體

android:typeface="monospace" //設置字型。字形有:normal, sans, serif,monospace

5、EditText是否可編輯

Android:editable // 是否可編輯

6、在EditText中軟鍵盤的調起、關閉

(1)EditText有焦點(focusable為true)阻止輸入法彈出

editText=(EditText)findViewById(R.id.txtBody);

editText.setOnTouchListener(new OnTouchListener(){

public boolean onTouch(View v, MotionEvent event){

editText.setInputType(InputType.TYPE_NULL); //關閉軟鍵盤

return false;

}

});

(2)當EidtText無焦點(focusable=false)時阻止輸入法彈出

InputMethodManager imm =

(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(editText.getWindowToken(),0);

(3)調用數字鍵盤并設置輸入類型和鍵盤為英文

etNumber.setInputType(InputType.TYPE_CLASS_NUMBER); //調用數字鍵盤

rlEditText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);//設置輸入類型和鍵盤為英文 或者:android:inputType="textUri|textMultiLine"

(4)android:focusable="false"//鍵盤永遠不會彈出

//不自動彈出鍵盤

//關閉鍵盤(比如輸入結束后執行) InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(etEditText.getWindowToken(), 0);

//自動彈出鍵盤

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);

etEditText.requestFocus();//讓EditText獲得焦點,但是獲得焦點并不會自動彈出鍵盤

7、android:layout_gravity和android:gravity的區別

(1)android:layout_gravity是本元素對父元素的重力方向。

(2)android:gravity是本元素所有子元素的重力方向。

8、android:padding和android:layout_margin區別

這兩個都可以設置邊距,但有細微的區別:

(1)android:padding是相對父view的邊距

(2)android:layout_margin是相對同一級View的邊距

例:LinearLayout是水平布局,下面有兩個按鈕,

(a)如果右邊的按鈕想距左邊的按鈕15px,因為這兩個按鈕是同一級的,應該用android:layout_margin;

(b)如果右邊的按鈕想距左邊的距離為350px,應該用android:padding

9、android:numeric//只接受數字

android:numeric來控制輸入的數字類型,一共有三種分別為integer(正整數)、signed(帶符號整數,有正負)和decimal(浮點數)。

10、Enter鍵圖標的設置

軟鍵盤的Enter鍵默認顯示的是“完成”文本,我們知道按Enter建表示前置工作已經準備完畢了,要去什么什么啦。比如,在一個搜索中,我們輸入要搜索的文本,然后按Enter表示要去搜索了,但是默認的Enter鍵顯示的是“完成”文本,看著不太合適,不符合搜索的語義,如果能顯示“搜索”兩個字或者顯示一個表示搜索的圖標多好。事實證明我們的想法是合理的,Android也為我們提供的這樣的功能。通過設置android:imeOptions來改變默認的“完成”文本。這里舉幾個常用的常量值:

(1)actionUnspecified未指定,對應常量EditorInfo.IME_ACTION_UNSPECIFIED效果:

(2)actionNone 沒有動作,對應常量EditorInfo.IME_ACTION_NONE效果:

(3)actionGo去往,對應常量EditorInfo.IME_ACTION_GO 效果:

(4)actionSearch 搜索,對應常量EditorInfo.IME_ACTION_SEARCH效果:

(5)actionSend 發送,對應常量EditorInfo.IME_ACTION_SEND效果:

(6)actionNext 下一個,對應常量EditorInfo.IME_ACTION_NEXT效果:

(7)actionDone 完成,對應常量EditorInfo.IME_ACTION_DONE效果:

11、使用android:imeOptinos可對Android自帶的軟鍵盤進行一些界面上的設置:

android:imeOptions="flagNoExtractUi"?//使軟鍵盤不全屏顯示,只占用一部分屏幕 同時,這個屬性還能控件軟鍵盤右下角按鍵的顯示內容,默認情況下為回車鍵 android:imeOptions="actionNone"?//輸入框右側不帶任何提示 android:imeOptions="actionGo"???//右下角按鍵內容為'開始' android:imeOptions="actionSearch"?//右下角按鍵為放大鏡圖片,搜索 android:imeOptions="actionSend"???//右下角按鍵內容為'發送' android:imeOptions="actionNext"??//右下角按鍵內容為'下一步' android:imeOptions="actionDone"?//右下角按鍵內容為'完成'

12、限定edittext能輸入數字和字母,并且默認輸入為數字,如身份證號碼

android:inputType="number" android:digits="0123456789xyzXYZ"

13、軟鍵盤的調起導致原來的界面被擠上去,或者導致界面下面的tab導航被擠上去,解決方法如下

解決方法:

使用Manifest中的Activity的android:windowSoftInputMode的"adjustPan"屬性。

另外注意:有關軟鍵盤的問題可參考android:windowSoftInputMode中屬性。

14、edittext光標詳解?edittext.requestFocusFromTouch();//讓光標放入到點擊位置。 edittext.requestFocus();//默認方式獲得焦點

EditText editor = (EditText)getCurrentView();//光標處插入 int cursor = editor.getSelectionStart(); editor.getText().insert(cursor,delta);

讓光標移到末端(這樣文字就會向前顯示) EditText et = ... String text = "text"; et.setText(text); et.setSelection(text.length());

android:cursorVisible="false" 隱藏光標

android:background="#00000000"//不要文本框背景

有時候也要對intent的默認焦點進行設置,不至于在intent跳轉的時候默認焦點(光標)在EditText上,導致進入intent就打開輸入法,影響界面美觀。

默認焦點的順序是:從上倒下

從左到右第一個可以輸入的控件作為焦點

可以使用:

button.setFocusable(true);

button.requestFocus();

button.setFocusableInTouchMode(true);

也可以:

在EditText前面放置一個看不到的LinearLayout,讓他率先獲取焦點:

android:focusable="true"

android:focusableInTouchMode="true"

android:layout_width="0px"

android:layout_height="0px"/>

Android?EditText?屬性匯總

Android EditText 屬性匯總

android:layout_gravity="center_vertical" 設置控件顯示的位置:默認top,這里居中顯示,還有bottom android:hint="請輸入數字!"

設置顯示在空間上的提示信息 android:numeric="integer" 設置只能輸入整數,如果是小數則是:

decimal android:singleLine="true" 設置單行輸入,一旦設置為true,則文字不會自動換行。

android:password="true" 設置只能輸入密碼

android:textColor = "#ff8c00" 字體顏色

android:textStyle="bold" 字體,bold, italic, bolditalic android:textSize="20dip" 大小

android:capitalize = "characters" 以大寫字母寫

android:textAlign="center" EditText沒有這個屬性,但TextView有 android:textColorHighlight="#cccccc" 被選中文字的底色,默認為藍色

android:textColorHint="#ffff00" 設置提示信息文字的顏色,默認為灰色 android:textScaleX="1.5" 控制字與字之間的間距

android:typeface="monospace" 字型,normal, sans, serif, monospace android:background="@null" 空間背景,這里沒有,指透明

android:layout_weight="1" 權重,控制控件之間的地位,在控制控件顯示的大小時蠻有用的。

android:textAppearance="?android:attr/textAppearanceLargeInverse" 文字外觀,這里引用的是系統自帶的一個外觀,?表示系統是否有這種外觀,否則使用默認的外觀。不知道這樣理解對不對? 通過EditText的layout xml文件中的相關屬性來實現:

1. 密碼框屬性 android:password="true" 這條可以讓EditText顯示的內容自動為星號,輸入時內容會在1秒內變成*字樣。

2. 純數字 android:numeric="true" 這條可以讓輸入法自動變為數字輸入鍵盤,同時僅允許0-9的數字輸入

3. 僅允許 android:capitalize="cwj1987" 這樣僅允許接受輸入cwj1987,一般用于密碼驗證 下面是一些擴展的風格屬性

android:editable="false" 設置EditText不可編輯

android:singleLine="true" 強制輸入的內容在單行

android:ellipsize="end" 自動隱藏尾部溢出數據,一般用于文字內容過長一行無法全部顯示時

實現在EditText中輸入自定義表情,需要將放在drawable中的表情圖片,嵌入到EditText中,這里利用ImageSpan實現該功能。

第一步:利用反射機制,得到圖片資源的ID,生成圖片bitmap對象

Field field = R.drawable.class.getDeclaredField("image" + random);

int resouceId = Integer.parseInt(field.get(null).toString());

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resouceId);

第二步:創建imageSpan對象,將imageSpan對象加載到spannableString中

ImageSpan span = new ImageSpan(getApplicationContext(), bitmap);

SpannableString spanna = new SpannableString("image");

spanna.setSpan(span, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

第三步:將SpannableString對象加到EditText中

edittext.append(spanna);

如何在EditText中限定輸入字符的方式:

1.通過設置digits屬性限定輸入的字符:android:digits="0123456789"

2.通過設置inputtype屬性選擇輸入字符類型:android:inputType="number"

3.通過設置numberic屬性接受數字輸入:android:numeric="integer"

android:inputType來設置文本的類型,讓輸入法選擇合適的軟鍵盤的.

android:numeric來控制輸入的數字類型,一共有三種分別為integer(正整數)、signed

(帶符號整數)和decimal(浮點數).

版權聲明:本文為博主原創文章,未經博主允許不得轉載。

總結

以上是生活随笔為你收集整理的edtext 从右边开始输入 安卓_Android开发之EditText属性详解的全部內容,希望文章能夠幫你解決所遇到的問題。

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