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

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

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

1.實現(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); //點擊對話框以外的位置,不消失
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自定義對話框?qū)嵗a的文章就介紹到這了,更多相關(guān)android對話框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android使用TextView,設(shè)置onClick屬性無效的解決方法

    Android使用TextView,設(shè)置onClick屬性無效的解決方法

    下面小編就為大家?guī)硪黄狝ndroid使用TextView,設(shè)置onClick屬性無效的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • Android TextView預(yù)渲染研究

    Android TextView預(yù)渲染研究

    這篇文章主要介紹了Android TextView預(yù)渲染研究的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • Android編程基于距離傳感器控制手機屏幕熄滅的方法詳解

    Android編程基于距離傳感器控制手機屏幕熄滅的方法詳解

    這篇文章主要介紹了Android編程基于距離傳感器控制手機屏幕熄滅的方法,結(jié)合具體實例形式分析了Android距離傳感器的控制屏幕熄滅的實現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下
    2017-11-11
  • Android實現(xiàn)自定義圓形進(jìn)度條

    Android實現(xiàn)自定義圓形進(jìn)度條

    這篇文章主要介紹了Android自定義圓形進(jìn)度條實現(xiàn)代碼,進(jìn)度條在Android中教程經(jīng)常使用到,本文向大家分享了Android實現(xiàn)自定義圓形進(jìn)度條的代碼,感興趣的小伙伴們可以參考一下
    2016-03-03
  • 最新評論

    沅江市| 新密市| 绩溪县| 文成县| 郯城县| 都兰县| 广南县| 微山县| 醴陵市| 余姚市| 洞头县| 镇沅| 天气| 蒲城县| 扶风县| 丹寨县| 林口县| 昭苏县| 谢通门县| 海伦市| 北京市| 江孜县| 成都市| 阜阳市| 河北省| 唐河县| 肃北| 永修县| 石林| 当涂县| 清水县| 牙克石市| 清远市| 环江| 西峡县| 临城县| 岳阳市| 深州市| 乌拉特中旗| 阜平县| 依兰县|