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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

补10

發(fā)布時間:2025/4/5 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 补10 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

  • 涉及知識點(diǎn)
  • 創(chuàng)建安卓應(yīng)用
  • 將背景圖片拷貝到drawable目錄
  • 主布局資源文件
  • 字符串資源文件strings.xml
  • 主界面類
  • 查看效果

涉及知識點(diǎn)

1、線性布局(LinearLayout)
2、標(biāo)簽(TextView)
3、按鈕(Button)
4、編輯框(EditText)
5、單選按鈕組(RadioGroup)
6、單選按鈕(RadioButton)
7、復(fù)選框(CheckBox)

創(chuàng)建安卓應(yīng)用

將背景圖片拷貝到drawable目錄

主布局資源文件

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="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=".setbasic"android:background="@drawable/tt"android:orientation="vertical"android:paddingLeft="20dp"android:paddingRight="20dp"android:paddingTop="30dp"><TextViewandroid:id="@+id/tvSetInformation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginBottom="30dp"android:text="@string/set_information"android:textColor="#0000ff"android:textSize="30sp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_vertical"android:orientation="horizontal"><TextViewandroid:id="@+id/tvName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Name"android:textColor="#000000"android:textSize="16sp" /><EditTextandroid:id="@+id/edtName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ems="10"android:hint="@string/input_name"android:singleLine="true" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_vertical"android:orientation="horizontal"><TextViewandroid:id="@+id/tvGender"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/gender"android:textColor="#000000"android:textSize="16sp" /><RadioGroupandroid:id="@+id/rgGender"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/rbMale"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:text="@string/male" /><RadioButtonandroid:id="@+id/rbFemale"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:text="@string/female" /></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_vertical"android:orientation="horizontal"><TextViewandroid:id="@+id/tvHobby"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/hobby"android:textColor="#000000"android:textSize="16sp" /><CheckBoxandroid:id="@+id/cbMusic"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/music" /><CheckBoxandroid:id="@+id/cbRead"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/read" /><CheckBoxandroid:id="@+id/cbFood"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/food" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="30dp"><Buttonandroid:id="@+id/btnOk"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:onClick="doOK"android:text="@string/Ok" /><Buttonandroid:id="@+id/btnClear"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:onClick="doClear"android:text="@string/clear" /><Buttonandroid:id="@+id/btnExit"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:onClick="doExit"android:text="@string/exit" /></LinearLayout><TextViewandroid:id="@+id/tvResult"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="30dp"android:textSize="15sp" /></LinearLayout>

字符串資源文件strings.xml

<resources><string name="set_information">設(shè)置基本信息</string><string name="Name">姓名:</string><string name="input_name">請輸入姓名</string><string name="gender">性別:</string><string name="male">男</string><string name="female">女</string><string name="hobby">愛好:</string><string name="travel">旅行</string><string name="read">閱讀</string><string name="food">美食</string><string name="music">音樂</string><string name="Ok">確定</string><string name="clear">清除</string><string name="exit">退出</string></resources>

主界面類

package net.tp.xiangduibuju;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast;public class setbasic extends AppCompatActivity {private EditText edtName;private RadioGroup rgGender;private RadioButton rbMale;private RadioButton rbFemale;private CheckBox cbRead;private CheckBox cbMusic;private CheckBox cbFood;private TextView tvResult;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 利用布局資源文件設(shè)置用戶界面setContentView(R.layout.activity_setbasic);//通過資源標(biāo)識符獲得控件實(shí)例edtName=findViewById(R.id.edtName);rgGender=findViewById(R.id.rgGender);rbMale=findViewById(R.id.rbMale);rbFemale=findViewById(R.id.rbFemale);cbRead=findViewById(R.id.cbRead);cbMusic=findViewById(R.id.cbMusic);cbFood=findViewById(R.id.cbFood);tvResult=findViewById(R.id.tvResult);}/** 提交按鈕單擊事件處理方法* @param view*/public void doOK(View view){//獲取姓名String strName=edtName.getText().toString().trim();//獲取性別值String strGender="";//根據(jù)選中單選按鈕的Id進(jìn)行判斷switch (rgGender.getCheckedRadioButtonId()){case R.id.rbMale:strGender=rbMale.getText().toString();break;case R.id.rbFemale:strGender=rbFemale.getText().toString();break;}//獲取愛好StringBuilder builder =new StringBuilder();if(cbRead.isChecked()){builder.append(cbRead.getText().toString()+" ");}if (cbMusic.isChecked()){builder.append(cbMusic.getText().toString()+" ");}if (cbFood.isChecked()){builder.append(cbFood.getText().toString()+" ");}String strHobby = builder.toString().trim();//顯示基本信息if (!(strName.equals("")) && strHobby != "") {String result = "姓名:" + strName + "\n性別:" + strGender + "\n愛好:" + strHobby;tvResult.setText(result);} else {Toast.makeText(setbasic.this, "基本信息不全,請?zhí)顚懲耆笤偬峤?#34;,Toast.LENGTH_SHORT).show();}}public void doClear(View view){edtName.setText("");rbMale.setChecked(true);cbRead.setChecked(false);cbMusic.setChecked(false);cbFood.setChecked(false);tvResult.setText("");}public void doExit(View view){finish();} }

查看效果



總結(jié)

以上是生活随笔為你收集整理的补10的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。