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

Android Studio實(shí)現(xiàn)單選對(duì)話框

 更新時(shí)間:2022年05月17日 10:39:57   作者:言人冰  
這篇文章主要為大家詳細(xì)介紹了Android Studio實(shí)現(xiàn)單選對(duì)話框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)單選對(duì)話框的具體代碼,供大家參考,具體內(nèi)容如下

上效果圖

activity_main.xml

<?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=".MainActivity"
? ? android:orientation="vertical"
? ? >
? ? <TextView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="單選對(duì)話框"
? ? ? ? android:textSize="20sp"
? ? ? ? android:layout_marginTop="30dp"
? ? ? ? android:gravity="center"
? ? ? ? android:id="@+id/tv"
? ? ? ? />
? ? <Button
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="設(shè)置字體大小"
? ? ? ? android:id="@+id/btn"
? ? ? ? android:layout_marginTop="20dp"
? ? ? ? android:layout_gravity="center"
? ? ? ? />

</LinearLayout>

MainActivity.java

package com.example.singlechoicedialog;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
? ? private AlertDialog dialog;
? ? private TextView textView;
? ? private int[] textSizeArr = {10,20,25,30,40};//存儲(chǔ)字體大小
? ? private ?String[] fontStyleArr= {"小號(hào)","默認(rèn)","中號(hào)","大號(hào)","超大"};//存儲(chǔ)樣式
? ? int textSize = 1; //單選列表中默認(rèn)選擇的位置
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //設(shè)置監(jiān)聽
? ? ? ? findViewById(R.id.btn).setOnClickListener(this); //為id為btn的按鈕邦定監(jiān)聽
? ? ? ? textView = (TextView) findViewById(R.id.tv);

? ? }

? ? @Override
? ? public void onClick(View view) {
? ? ? ? // ?創(chuàng)建對(duì)話框并設(shè)置其樣式(這里采用鏈?zhǔn)椒匠?
? ? ? ? AlertDialog.Builder builder = new AlertDialog.Builder(this)//設(shè)置單選框列表
? ? ? ? ? ? ? ? .setTitle("設(shè)置字體的大小") ? //設(shè)置標(biāo)題
? ? ? ? ? ? ? ? .setIcon(R.drawable.bdd) //設(shè)置圖標(biāo)
? ? ? ? ? ? ? ? .setSingleChoiceItems(fontStyleArr, textSize, new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialogInterface, int i) {
? ? ? ? ? ? ? ? ? ? ? ? textSize=i; //在OnClick方法中得到被點(diǎn)擊的序號(hào) i
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? .setPositiveButton("確定", new DialogInterface.OnClickListener() {//在對(duì)話框中設(shè)置“確定”按鈕
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialogInterface, int i) {
? ? ? ? ? ? ? ? ? ? ? ? //為TextView設(shè)置在單選對(duì)話框中選擇的字體大小
? ? ? ? ? ? ? ? ? ? ? ? textView.setTextSize(textSizeArr[textSize]);
? ? ? ? ? ? ? ? ? ? ? ? //設(shè)置好字體大小后關(guān)閉單選對(duì)話框
? ? ? ? ? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? .setNegativeButton("取消", new DialogInterface.OnClickListener() {//在對(duì)話框中設(shè)置”取消按鈕“
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialogInterface, int i) {
? ? ? ? ? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? dialog = builder.create();
? ? ? ? dialog.show();
? ? }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android高德地圖marker自定義彈框窗口

    Android高德地圖marker自定義彈框窗口

    這篇文章主要為大家詳細(xì)介紹了Android高德地圖marker自定義彈框窗口,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android開發(fā)實(shí)現(xiàn)布局中為控件添加選擇器的方法

    Android開發(fā)實(shí)現(xiàn)布局中為控件添加選擇器的方法

    這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)布局中為控件添加選擇器的方法,涉及Android開發(fā)中布局設(shè)置的相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • Android實(shí)現(xiàn)垂直跑馬燈效果

    Android實(shí)現(xiàn)垂直跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)垂直跑馬燈效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Kotlin 擴(kuò)展函數(shù)和擴(kuò)展屬性的使用方法

    Kotlin 擴(kuò)展函數(shù)和擴(kuò)展屬性的使用方法

    這篇文章主要介紹了Kotlin 擴(kuò)展函數(shù)和擴(kuò)展屬性的使用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • android連續(xù)拖動(dòng)導(dǎo)致掛起的解決方法

    android連續(xù)拖動(dòng)導(dǎo)致掛起的解決方法

    本文給大家分享的是在安卓的項(xiàng)目開發(fā)中遇到連續(xù)拖動(dòng)對(duì)象,導(dǎo)致掛起的問題的解決方法,也是經(jīng)過很多網(wǎng)友的提示,最終才找到解決方法,這里記錄一下,分享給大家。
    2015-05-05
  • Android本地視頻壓縮方案的示例代碼

    Android本地視頻壓縮方案的示例代碼

    本篇文章主要介紹了Android本地視頻壓縮方案的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android TextView仿微信可折疊效果

    Android TextView仿微信可折疊效果

    這篇文章主要為大家詳細(xì)介紹了Android TextView仿微信可折疊效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • android自定義等級(jí)評(píng)分圓形進(jìn)度條

    android自定義等級(jí)評(píng)分圓形進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了android自定義等級(jí)評(píng)分圓形進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android使用ContentResolver搜索手機(jī)通訊錄的方法

    Android使用ContentResolver搜索手機(jī)通訊錄的方法

    這篇文章主要介紹了Android使用ContentResolver搜索手機(jī)通訊錄的方法,結(jié)合實(shí)例形式分析了Android中ContentResolver操作手機(jī)通訊錄的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • android實(shí)現(xiàn)加載動(dòng)畫對(duì)話框

    android實(shí)現(xiàn)加載動(dòng)畫對(duì)話框

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)加載動(dòng)畫對(duì)話框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10

最新評(píng)論

葫芦岛市| 库伦旗| 尖扎县| 京山县| 睢宁县| 南郑县| 津市市| 新丰县| 壤塘县| 三江| 镇远县| 石屏县| 登封市| 册亨县| 庆云县| 洪雅县| 临清市| 大洼县| 兴隆县| 南阳市| 南昌市| 临颍县| 饶平县| 南阳市| 特克斯县| 永和县| 苏尼特右旗| 缙云县| 县级市| 青浦区| 镇雄县| 桐庐县| 崇礼县| 公安县| 梅河口市| 汪清县| 石台县| 花莲市| 玉龙| 宜良县| 潞西市|