亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android自定義對(duì)話框?qū)嵗a

 更新時(shí)間:2021年12月30日 09:58:14   作者:扒雞撕坦  
大家好,本篇文章主要講的是android自定義對(duì)話框?qū)嵗a,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽

1.實(shí)現(xiàn)效果

??

2.定義dialog.xml (res/layout/dialog.xml)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
 
    <RelativeLayout
        android:layout_width="250sp"
        android:layout_height="270sp"
        android:layout_centerInParent="true">
 
        <TextView
            android:id="@+id/dialog_title"
            android:layout_width="wrap_content"
            android:layout_height="35sp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="15sp"
            android:textColor="#333333"
            android:textSize="17sp" />
 
        <TextView
            android:id="@+id/dialog_message"
            android:layout_width="wrap_content"
            android:layout_height="160sp"
            android:layout_centerInParent="true"
            android:layout_marginTop="65sp"
            android:textColor="#333333"
            android:textSize="17sp" />
 
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30sp"
            android:layout_marginBottom="20sp"
            android:orientation="horizontal">
 
            <LinearLayout
                android:id="@+id/dialog_confirm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
 
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/confirm_button_style"
                    android:gravity="center"
                    android:text="確定"
                    android:textColor="@color/white"
                    android:textSize="18sp" />
            </LinearLayout>
 
            <LinearLayout
                android:id="@+id/dialog_cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="22sp">
 
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cancel_button_style"
                    android:gravity="center"
                    android:text="取消"
                    android:textColor="@color/teal_200"
                    android:textSize="18sp" />
            </LinearLayout>
        </LinearLayout>
 
    </RelativeLayout>
</RelativeLayout>

3. 設(shè)置確定、取消按鈕的background

上文的dialog.xml中,確定和取消按鈕都是TextView,所以需要自定義按鈕的背景

confirm_button_style.xml? (所有的color需要自定義)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="1000sp"/>
    <solid android:color="@color/teal_200"/>
    <stroke
        android:width="0.5sp"
        android:color="@color/colorAccent"/>
    <size android:width="105sp" android:height="40sp"/>
</shape>

cancel_button_style.xml?

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="1000sp"/>
    <solid android:color="@color/white"/>
    <stroke
        android:width="0.5sp"
        android:color="@color/teal_200"/>
    <size android:width="105sp" android:height="40sp"/>
</shape>

4. 自定義dialog的使用

final AlertDialog dialog = new AlertDialog.Builder(xxxClass.this).create();
dialog.setCancelable(false); //點(diǎn)擊對(duì)話框以外的位置,不消失
dialog.show();
 
Window window = dialog.getWindow();
window.setContentView(R.layout.dialog);
//標(biāo)題
TextView title = window.findViewById(R.id.dialog_title);
title.setText("dialog_title");
 
//內(nèi)容
TextView message = window.findViewById(R.id.dialog_message);
message.setText("dialog_message ");
 
//確定按鈕
LinearLayout confirm = window.findViewById(R.id.dialog_confirm);
confirm.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //xxx
    }
});
 
//取消按鈕
LinearLayout cancel = window.findViewById(R.id.dialog_cancel);
cancel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //xxx
    }
});

到此這篇關(guān)于android自定義對(duì)話框?qū)嵗a的文章就介紹到這了,更多相關(guān)android對(duì)話框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • IDEA打包jar-解決找不到或無(wú)法加載主類 main的問(wèn)題

    IDEA打包jar-解決找不到或無(wú)法加載主類 main的問(wèn)題

    這篇文章主要介紹了IDEA打包jar-解決找不到或無(wú)法加載主類 main的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能

    Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能

    這篇文章主要為大家詳細(xì)介紹了Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android?EventBus粘性事件實(shí)現(xiàn)機(jī)制探究

    Android?EventBus粘性事件實(shí)現(xiàn)機(jī)制探究

    最近項(xiàng)目做組件化,需要進(jìn)行組件化的通信,有時(shí)候可能會(huì)出現(xiàn)異步的情況,事件接收方還沒(méi)準(zhǔn)備好事件就已經(jīng)發(fā)送過(guò)來(lái)了,這時(shí)候想到了EventBus的粘性事件,這篇文章主要給大家介紹了關(guān)于Android?EventBus粘性事件實(shí)現(xiàn)機(jī)制的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • Android Toast使用的簡(jiǎn)單小結(jié)(推薦)

    Android Toast使用的簡(jiǎn)單小結(jié)(推薦)

    這篇文章主要介紹了Android Toast使用的簡(jiǎn)單小結(jié),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Android短信驗(yàn)證服務(wù)分享

    Android短信驗(yàn)證服務(wù)分享

    這篇文章主要為大家詳細(xì)介紹了Android短信驗(yàn)證服務(wù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Android開(kāi)啟新線程播放背景音樂(lè)

    Android開(kāi)啟新線程播放背景音樂(lè)

    這篇文章主要為大家詳細(xì)介紹了Android開(kāi)啟新線程播放背景音樂(lè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Kotlin學(xué)習(xí)教程之函數(shù)的默認(rèn)參數(shù)

    Kotlin學(xué)習(xí)教程之函數(shù)的默認(rèn)參數(shù)

    這篇文章主要給大家介紹了關(guān)于Kotlin學(xué)習(xí)教程之函數(shù)的默認(rèn)參數(shù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android編程使用ListView實(shí)現(xiàn)數(shù)據(jù)列表顯示的方法

    Android編程使用ListView實(shí)現(xiàn)數(shù)據(jù)列表顯示的方法

    這篇文章主要介紹了Android編程使用ListView實(shí)現(xiàn)數(shù)據(jù)列表顯示的方法,實(shí)例分析了Android中ListView控件的使用技巧,需要的朋友可以參考下
    2016-01-01
  • android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法

    android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Android UI繪制流程及原理詳解

    Android UI繪制流程及原理詳解

    在本篇文章里小編給大家整理的是關(guān)于Android UI繪制流程及原理以及相關(guān)知識(shí)點(diǎn),需要的朋友們可以學(xué)習(xí)下。
    2019-08-08

最新評(píng)論