最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 多種dialog的實現(xiàn)方法(推薦)

 更新時間:2018年01月29日 12:09:00   作者:遲暮有話說  
下面小編就為大家分享一篇Android 多種dialog的實現(xiàn)方法(推薦),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

要求:設計如下界面,包括圖片按鈕、復選按鈕、單選按鈕、普通按鈕,單擊按鈕彈出對話框,運行效果如下:

string.xml文件源代碼:

<resources>
  <string name="app_name">多種彈出對話框</string>
  <string name="dialog_img">圖片按鈕</string>
  <string name="dialog_radio">單選按鈕</string>
  <string name="dialog_box">復選按鈕</string>
  <string name="close">關閉</string>
</resources>

布局文件源代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
 <ImageView
   android:id="@+id/img"
   android:layout_height="100dp"
   android:layout_width="100dp"
   android:src="@drawable/aa"/>
  <CheckBox
    android:id="@+id/Checkbox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Chinese"/>
  <CheckBox
    android:id="@+id/Checkbox2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="English"
    android:checked="true"/>
  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="復選按鈕確定"/>
  <RadioGroup
    android:id="@+id/radioGroup"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <RadioButton
      android:id="@+id/male"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="male" />
    <RadioButton
      android:id="@+id/female"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:checked="true"
      android:text="female"/>
  </RadioGroup>
  <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="單選按鈕確定"/>
</LinearLayout>

java文件源代碼:

package com.example.shiyan1_4;
import android.app.Dialog;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import static android.R.attr.id;
public class Shiyan1_4Activity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shiyan1_4);
    ImageView img = (ImageView) findViewById(R.id.img);
    Button button1 = (Button) findViewById(R.id.button1);
    Button button2 = (Button) findViewById(R.id.button2);
    img.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        AlertDialog.Builder dialog1 = new AlertDialog.Builder(Shiyan1_4Activity.this);
        dialog1.setTitle(R.string.dialog_img)
            .setMessage("您點擊了圖片按鈕!")
            .setNegativeButton(R.string.close, null)
            .create()
            .show();
      }
    });
    button1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        AlertDialog.Builder dialog1 = new AlertDialog.Builder(Shiyan1_4Activity.this);
        String str1 = "";
        //獲取復選按鈕的值
        CheckBox Checkbox1 = (CheckBox)findViewById(R.id.Checkbox1);
        if(Checkbox1.isChecked()){
          str1 += Checkbox1.getText() + "is selected !";
        }
        CheckBox Checkbox2 = (CheckBox)findViewById(R.id.Checkbox2);
        if(Checkbox2.isChecked()){
          str1 += Checkbox2.getText() + " is selected !\n";
        }
        dialog1.setTitle(R.string.dialog_box)
            .setMessage(str1)
            .setNegativeButton(R.string.close, null)
            .create()
            .show();
      }
    });
    button2.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        AlertDialog.Builder dialog2 = new AlertDialog.Builder(Shiyan1_4Activity.this);
        String str2 = "";
        //獲取單選按鈕的值
        RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radioGroup);
        for (int i = 0; i <radioGroup.getChildCount(); i++){
          RadioButton radioButton = (RadioButton) radioGroup.getChildAt(i);
          if(radioButton.isChecked()){
            str2 += radioButton.getText() + " is selected !";
            break;
          }
        }
        dialog2.setTitle(R.string.dialog_radio)
            .setMessage(str2)
            .setNegativeButton(R.string.close, null)
            .create()
            .show();
      }
    });
  }
}

以上這篇Android 多種dialog的實現(xiàn)方法(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Android實現(xiàn)圖片隨手指旋轉功能

    Android實現(xiàn)圖片隨手指旋轉功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)圖片隨手指旋轉功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android Studio3安裝圖文教程

    Android Studio3安裝圖文教程

    這篇文章主要為大家詳細介紹了Android Studio3安裝圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Kotlin StateFlow單數(shù)據(jù)更新熱流設計與使用介紹

    Kotlin StateFlow單數(shù)據(jù)更新熱流設計與使用介紹

    StateFlow當值發(fā)生變化,就會將值發(fā)送出去,下流就可以接收到新值。在某些場景下,StateFlow比LiveData更適用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-09-09
  • Android Sqlite命令詳解(基本命令)

    Android Sqlite命令詳解(基本命令)

    這篇文章主要介紹了Android Sqlite命令詳解(基本命令)的相關資料,需要的朋友可以參考下
    2015-12-12
  • Android中掃描多媒體文件操作詳解

    Android中掃描多媒體文件操作詳解

    這篇文章主要介紹了Android中掃描多媒體文件操作詳解,本文講解了Android中的多媒體文件掃描機制、如何掃描一個剛創(chuàng)建的文件、如何掃描多個文件,需要的朋友可以參考下
    2015-01-01
  • Android Coil對比Glide深入分析探究

    Android Coil對比Glide深入分析探究

    這篇文章主要介紹了Android Coil對比Glide,Coil是Android上的一個全新的圖片加載框架,它的全名叫做coroutine image loader,即協(xié)程圖片加載庫
    2023-02-02
  • Android?MPAndroidChart繪制原理

    Android?MPAndroidChart繪制原理

    這篇文章主要介紹了Android?MPAndroidChart繪制原理,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08
  • Android Intent發(fā)送廣播消息實例詳解

    Android Intent發(fā)送廣播消息實例詳解

    這篇文章主要介紹了Android Intent發(fā)送廣播消息實例詳解的相關資料,需要的朋友可以參考下
    2017-04-04
  • OpenHarmony實現(xiàn)屏幕亮度動態(tài)調節(jié)方法詳解

    OpenHarmony實現(xiàn)屏幕亮度動態(tài)調節(jié)方法詳解

    大家在拿到dayu之后,都吐槽說,會經常熄屏,不利于調試,那么有沒有一種辦法,可以讓app不熄屏呢,答案是有的,今天我們就來揭秘一下,如何控制屏幕亮度
    2022-11-11
  • Android開發(fā)之時間日期組件用法實例

    Android開發(fā)之時間日期組件用法實例

    這篇文章主要介紹了Android開發(fā)之時間日期組件用法,主要介紹了TimePicker和DatePicker組件,對于Android程序開發(fā)有不錯的借鑒價值,需要的朋友可以參考下
    2014-08-08

最新評論

东安县| 新津县| 维西| 延安市| 霸州市| 黑山县| 龙泉市| 杭锦后旗| 宝丰县| 郯城县| 黎川县| 郯城县| 喀喇| 喀喇| 禹城市| 西充县| 三都| 额尔古纳市| 华池县| 孝义市| 西丰县| 凤阳县| 黄石市| 秦安县| 新民市| 宁津县| 宁都县| 陈巴尔虎旗| 云南省| 延庆县| 剑川县| 嘉义市| 苏尼特右旗| 天镇县| 竹北市| 福安市| 江西省| 连南| 修文县| 泰顺县| 冀州市|