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

Android?Studio使用自定義對(duì)話(huà)框效果

 更新時(shí)間:2022年05月17日 17:20:19   作者:徐為波  
這篇文章主要為大家詳細(xì)介紹了Android?Studio使用自定義對(duì)話(huà)框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Android Studio基礎(chǔ)使用自定義對(duì)話(huà)框,供大家參考,具體內(nèi)容如下

兼容低版本的APP運(yùn)行

第一步:新建新的空白activity,布局XML設(shè)置如下

該APP的啟動(dòng)界面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">
?
? ? <Button
? ? ? ? android:id="@+id/btn_single"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="顯示單選對(duì)話(huà)框"/>
? ? <Button
? ? ? ? android:id="@+id/btn_alert_customer"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="自定義對(duì)話(huà)框"/>
?
</LinearLayout>

自定義的對(duì)話(huà)框item_alert_dialog的布局XML設(shè)置

<?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">
?
? ? <Button
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="自定義Dialog界面!"
? ? ? ? />
? ? <TextView
? ? ? ? android:layout_width="250dp"
? ? ? ? android:layout_height="250dp"
? ? ? ? android:background="@mipmap/ic_launcher"/>
?
</LinearLayout>

第二步:在MainActivity.java中綁定布局xml

第三步:對(duì)話(huà)框?qū)崿F(xiàn)抽象方式

package com.xwb.zdydhk;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? Button btn_single = findViewById(R.id.btn_single);
? ? ? ? btn_single.setOnClickListener(this);
? ? ? ? Button btn_alert_customer = findViewById(R.id.btn_alert_customer);
? ? ? ? btn_alert_customer.setOnClickListener(this);
? ? }
? ? @Override
? ? public void onClick(View v){
? ? ? ? AlertDialog.Builder builder = new AlertDialog.Builder(this);
? ? ? ? switch (v.getId()){
? ? ? ? ? ? case R.id.btn_single:
? ? ? ? ? ? ? ? builder.setTitle("單選對(duì)話(huà)框").setIcon(R.mipmap.ic_launcher).setSingleChoiceItems(new String[]{"中國(guó)", "德國(guó)", "日本"}, 0, new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int which) {
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"選中的"+which,Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.btn_alert_customer:
? ? ? ? ? ? ? ? //setView(R.layout.item_alert_dialog)為自定義的對(duì)話(huà)框,或圖片等等
? ? ? ? ? ? ? ? builder.setTitle("自定義對(duì)話(huà)框").setIcon(R.mipmap.ic_launcher).setView(R.layout.item_alert_dialog);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? AlertDialog ad = builder.create();
? ? ? ? ad.show();
? ? }
}

第四步:運(yùn)行APP效果

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

相關(guān)文章

最新評(píng)論

河西区| 新巴尔虎左旗| 诏安县| 谢通门县| 厦门市| 尤溪县| 苍南县| 尼木县| 西青区| 玛曲县| 皮山县| 平谷区| 镇康县| 大英县| 凤翔县| 宜阳县| 黄冈市| 大悟县| 积石山| 托克逊县| 迁安市| 江油市| 永兴县| 铅山县| 安新县| 汉寿县| 南投市| 宜宾县| 桐城市| 偏关县| 禹城市| 阜城县| 岳阳市| 抚松县| 丹江口市| 漳平市| 华容县| 英吉沙县| 抚顺市| 凭祥市| 屯留县|