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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android入门之常用控件

發(fā)布時(shí)間:2024/4/15 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android入门之常用控件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

今天復(fù)習(xí)android 基礎(chǔ)入門(mén)突然心血來(lái)潮,然后。。。



首先布局:


具體代碼:

import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Toast;public class MainActivity extends AppCompatActivity {private Button button;private EditText text;private ImageView imageView;private ProgressBar progressBar;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button=(Button) findViewById(R.id.button);text=(EditText) findViewById(R.id.edit_text);imageView=(ImageView) findViewById(R.id.image);progressBar=(ProgressBar) findViewById(R.id.progressbar);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//獲取EditText輸入的內(nèi)容String data=text.getText().toString();Toast.makeText(MainActivity.this,data,Toast.LENGTH_SHORT).show();//按鈕點(diǎn)擊事件改變圖片imageView.setImageResource(R.drawable.img_2);//按鈕點(diǎn)擊事件顯示和隱藏進(jìn)度if (progressBar.getVisibility()==View.GONE){progressBar.setVisibility(View.VISIBLE);}else{progressBar.setVisibility(View.GONE);}//按鈕點(diǎn)擊事件增加進(jìn)度條int progress=progressBar.getProgress();progress=progress+10;progressBar.setProgress(progress);/*** AlertDialog的使用*/AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);//創(chuàng)建一個(gè)AlertDialog實(shí)例dialog.setTitle("這是一個(gè)對(duì)話框");//設(shè)置標(biāo)題dialog.setMessage("重要的提示");//設(shè)置內(nèi)容dialog.setCancelable(false);//可否用back鍵關(guān)閉對(duì)話框等屬性dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {//為對(duì)話框設(shè)置確定按鈕的點(diǎn)擊事件@Overridepublic void onClick(DialogInterface dialog, int which) {}});dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {//設(shè)置取消按鈕的點(diǎn)擊事件@Overridepublic void onClick(DialogInterface dialog, int which) {}});dialog.show();//將對(duì)話框顯示/*** ProgressDialog的使用*/ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);//創(chuàng)建ProgressDialog實(shí)例progressDialog.setTitle("這是進(jìn)度條彈出框");//設(shè)置標(biāo)題progressDialog.setMessage("加載中");//設(shè)置內(nèi)容progressDialog.setCancelable(true);//可否取消progressDialog.show();//講進(jìn)度彈出框顯示出來(lái)}});} }





總結(jié)

以上是生活随笔為你收集整理的Android入门之常用控件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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