【问题标题】:XML for AlertDialog? [duplicate]警报对话框的 XML? [复制]
【发布时间】:2019-12-19 12:03:21
【问题描述】:

我对标准 AlertDialog 的外观非常满意。有一个“是按钮”和一个“否按钮”。

但是我希望我的 AlertDialog 也有一个带有监听器的开关。据我了解,我需要创建自己的自定义 AlertDialog 来实现这一点。

我的问题是我能找到标准 AlertDialog 及其按钮的 XML 文件吗?

编辑:我知道如何创建自定义警报对话框。我正在寻找标准警报对话框的 XML。这样我就可以用它作为模板来构建我的自定义警报对话框。

【问题讨论】:

    标签: java android


    【解决方案1】:

    这是从AndroidX AppCompat library 的标准jar 文件中检索到的标准AlertDialog 的xml:

    abc_alert_dialog_material.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!--
         Copyright (C) 2015 The Android Open Source Project
    
         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at
    
              http://www.apache.org/licenses/LICENSE-2.0
    
         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
    -->
    
    <androidx.appcompat.widget.AlertDialogLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/parentPanel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start|left|top"
        android:orientation="vertical">
    
        <include layout="@layout/abc_alert_dialog_title_material"/>
    
        <FrameLayout
            android:id="@+id/contentPanel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="48dp">
    
            <View android:id="@+id/scrollIndicatorUp"
                  android:layout_width="match_parent"
                  android:layout_height="1dp"
                  android:layout_gravity="top"
                  android:background="?attr/colorControlHighlight"
                  android:visibility="gone"/>
    
            <androidx.core.widget.NestedScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
    
                    <android.widget.Space
                        android:id="@+id/textSpacerNoTitle"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/abc_dialog_padding_top_material"
                        android:visibility="gone"/>
    
                    <TextView
                        android:id="@android:id/message"
                        style="@style/TextAppearance.AppCompat.Subhead"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingLeft="?attr/dialogPreferredPadding"
                        android:paddingRight="?attr/dialogPreferredPadding"/>
    
                    <android.widget.Space
                        android:id="@+id/textSpacerNoButtons"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/abc_dialog_padding_top_material"
                        android:visibility="gone"/>
                </LinearLayout>
            </androidx.core.widget.NestedScrollView>
    
            <View android:id="@+id/scrollIndicatorDown"
                  android:layout_width="match_parent"
                  android:layout_height="1dp"
                  android:layout_gravity="bottom"
                  android:background="?attr/colorControlHighlight"
                  android:visibility="gone"/>
    
        </FrameLayout>
    
        <FrameLayout
            android:id="@+id/customPanel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="48dp">
    
            <FrameLayout
                android:id="@+id/custom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </FrameLayout>
    
        <include layout="@layout/abc_alert_dialog_button_bar_material"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"/>
    
    </androidx.appcompat.widget.AlertDialogLayout>
    

    【讨论】:

    • 很酷,谢谢! :)
    猜你喜欢
    • 2018-05-10
    • 2013-06-26
    • 2017-09-14
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多