文章插圖

文章插圖
和你一起終身學習,這里是程序員Android
本篇文章主要介紹 Android 開發中的部分知識點,通過閱讀本篇文章,您將收獲以下內容:
一、EditText 繼承關系一、EditText 繼承關系
二、EditText 常用舉例
三、EditText 自定義背景框
四、EditText自動檢測輸入內容
五、Edittext 密文顯示
六、EditText 限制只能輸入特定字符
七、EditText 輸入保存的字符串不能為空
EditText繼承關系 如下:
java.lang.Object
? android.view.View
? android.widget.TextView
? android.widget.EditText
二、EditText 常用舉例
EditText主要用于輸入和修改文本內容 。
限制只能輸入純文本內容舉例如下:
<EditText
android:id=”@+id/plain_text_input”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:inputType=”text”/>
三、EditText 自定義背景框xml 中使用EditText 控件
<!-- 自定義EditText 背景 --> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:background="@drawable/custom_edittext_background" android:gravity="center" android:hint="一、自定義EditText背景框" android:padding="8dp" android:textSize="16sp" />自定義 EditText 背景框
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 圓角--> <corners android:radius="5dp" /> <!--描邊--> <stroke android:width="1dp" android:color="@android:color/holo_blue_light" /></shape>實現效果
四、EditText自動檢測輸入內容xml 中使用EditText 控件
<!– 自動檢測輸入更正 –>
<EditText
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:autoText=”true”
android:hint=”二、自動檢測輸入更正屬性 autoText”
android:textColor=”#FF6100″ />
實現效果
五、Edittext 密文顯示xml 中使用EditText 控件
<!– 以密文的形式顯示 –>
<EditText
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”三、以密文的形式顯示密碼”
android:password=”true” />
實現效果
六、EditText 限制只能輸入特定字符
限定只能輸入阿拉伯數字實現如下:
xml 中使用EditText 控件
<!– 設置允許輸入的字符 –>
<EditText
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:digits=”123456789.+-*/n()”
android:hint=”四、設置限制允許輸入阿拉伯數字” />
實現效果
七、EditText 輸入保存的字符串不能為空
EditText常用來獲取用戶輸入內容,因為我們要規避用戶輸入的內容為空的情況 。
實現效果如下:
實現代碼如下:
【如何修改edittext下劃線顏色 editview去掉下劃線】public class EditTextMethod extends Activity { EditText mEditText; Button mBtn; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_edittext); mEditText = (EditText) findViewById(R.id.test_et); mBtn = (Button) findViewById(R.id.btn_commit); mBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (!TextUtils.isEmpty(mEditText.getText().toString().trim())) { Toast.makeText( EditTextMethod.this, "你輸入的字符串是:" + mEditText.getText().toString().trim(), 1).show(); } else { Toast.makeText(EditTextMethod.this, "輸入的字符串不能為空", 1).show(); } } }); }}
- 電腦網絡顯示感嘆號是怎么回事如何解決 電腦網絡為感嘆號時該怎么辦
- 阿里云服務器數據備份 阿里云服務器如何備份數據
- 如何注冊公司電子郵箱 企業注冊郵箱的步驟
- 如何讓男友放下前任 幫助男友走出前任陰影的辦法
- 58同城如何發布 58同城自己發布的怎么怎么找
- 如何品嘗葡萄酒
- 修改端口號命令 端口號可以隨便改嗎
- 如何查出電腦端口 怎么看電腦的端口
- 軟件證書過期如何解決方法 電腦軟件證書過期
- 精辟易懂 四字總結立夏如何養生
