Drawable:
drawable是抽象類。包括圖片,色塊,畫板,背景。
drawable-ldpi 存放低分辨率圖片。drawable-hdpi 高分辨率。drawable-xxhdpi 超高分辨率。
Android:src=”@drawable/image”?即可使用
Shape:
形狀圖形。圓角,矩形等常見幾何圖形,可以自定義畫內(nèi)置圖形。
屬性有:?<size>尺寸? <stroke>描邊 <corner>填充圓角
? ? ? ? ? ? ? <Solid>填充顏色 <padding>間隔 <gradient>漸變
九宮格圖片:
9.png (圖片拉伸的時候特定的區(qū)域不會發(fā)生圖片失真)
界面上邊的黑線指的是水平方向拉伸區(qū)域。
界面左邊的黑線指的是垂直方向拉伸區(qū)域。
界面下邊的黑線指的是該圖片作為控件背景時,內(nèi)部文字左右邊界放在黑線內(nèi)。
界面右邊的黑線指的是該圖片作為控件背景時,內(nèi)部文字上下邊界放在黑線內(nèi)。
狀態(tài)列表圖形:
根據(jù)狀態(tài)(是否被點擊)顯示不同圖形
<item android:state_pressed="true" ?android:drawable="@drawable/text"/>??選中
<item android:drawable="@drawable/text1"/>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?不選中
復(fù)選框CheckBox:
<CheckBox
android:id="@+id/ck_system"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="這是系統(tǒng)的CheckBox"/>
開關(guān)按鈕Switch:
Switch控件新添加的XML屬性說明如下:
textOn:設(shè)置右側(cè)開啟時的文本。
textOff: 設(shè)置左側(cè)關(guān)閉時的文本。
Track: 設(shè)置開關(guān)軌道的背景。
Thumb: 設(shè)置開關(guān)標(biāo)識的圖標(biāo)。
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_weight="1"
android:padding="5dp"
android:text="這是一個switch開關(guān)的文本"/>
<Switch
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:padding="5dp" />
單選按鈕RadioButton:
<RadioGroup
android:id="@+id/rg_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_male"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="男"/>
<RadioButton
android:id="@+id/rb_female"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="女"/>
</RadioGroup>
編輯框EditText:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background=”@null” //取消邊框
android:maxLength="16" //最大輸入文字
android:hint="請輸出用戶名" //提示文字
android:inputType="text"/> //輸入類型
焦點變更監(jiān)聽器:(用于驗證性)
et_phone = findViewById(R.id.et_phone); //獲取到號碼數(shù)據(jù)
EditText et_password=findViewById(R.id.et_password);
et_password.setOnFocusChangeListener(this); //焦點變更監(jiān)聽方式
//檢測焦點做判斷
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus)
{String phone= et_phone.getText().toString();
//手機(jī)號碼不足11位
if (TextUtils.isEmpty(phone)||phone.length()<11)
{ et_phone.requestFocus();
Toast.makeText(this,"請輸入11位手機(jī)號碼",Toast.LENGTH_SHORT).show();
}
}
}
文本變化監(jiān)聽器:
addTextChangedLinstener接口
有三個方法 ① beforeTextChange 文本改變前
? ? ? ? ? ? ? ? ? ?② onTextChanged 文本改變過程中
? ? ? ? ? ? ???????③afterTextChanged 文本改變之后文章來源:http://www.zghlxwxcb.cn/news/detail-644121.html
彈出類提醒對話框AlertDialog:
public void onClick(View view) {
//創(chuàng)建提醒對話框構(gòu)建器
AlertDialog.Builder builder =new AlertDialog.Builder(this);
builder.setTitle("尊敬的用戶");
//設(shè)置對話框的內(nèi)容文本
builder.setMessage("你真的要卸載我嘛?");
//設(shè)置對話框的肯定按鈕文本及其點擊監(jiān)聽
builder.setPositiveButton("殘忍卸載", (dialogInterface, i) -> {
tv_alert.setText("我滾了,你照顧好自己");
});
//設(shè)置對話框否定按鈕文本及監(jiān)聽
builder.setNegativeButton("我再想想",(dialogInterface, i) -> {
tv_alert.setText("你不離,我不棄");
});
//根據(jù)建造器構(gòu)建提醒對話框?qū)ο? AlertDialog dialog = builder.create();
//顯示提醒對話框
dialog.show(); }
日期對話框DatePickerDialog:
<DatePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:datePickerMode="spinner"
android:calendarViewShown="false"/>
時間對話框TimePickerDialog:
<TimePicker
android:id="@+id/tp_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
僅為個人筆記記錄使用文章來源地址http://www.zghlxwxcb.cn/news/detail-644121.html
到了這里,關(guān)于Android開發(fā)從0開始(圖形與按鈕)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!