显示Android Wear样式AlertDialog [英] Showing Android Wear style AlertDialog

查看:77
本文介绍了显示Android Wear样式AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Android Wear的设置"应用程序中重新创建警报对话框的方法:

I'm looking for a way to recreate the alert dialog in the Setting application of Android Wear:

将其滑动为可解雇的

但是,我得到的却是这样:

But instead, what I got is this:

只是一个准Android对话框.如何以Settings.apk样式显示AlertDialog? (我认为这是Android Wear应用程序的默认设置)

Just a barebone Android dialog. How can I show the AlertDialog in the Settings.apk style? (Which I think must be default for Android Wear application)

推荐答案

我没有找到执行此操作的默认方法,而且将自定义视图设置为AlertDialog的效果也不理想.您仍然可以尝试,也许可以使用其他主题.

I found no default way to do this, also setting a custom view to an AlertDialog did not look good. You can still try though, maybe a different Theme works.

我所做的是创建一个新的Activity并创建自己的布局,如下所示:

What I did was create a new Activity and create my own layout which looks like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="10dp"
        app:layout_box="all">

        <TextView
            android:id="@+id/tv_longtext"
            android:layout_width="match_parent"
            android:layout_height="0sp"
            android:layout_weight="1"
            android:fontFamily="sans-serif-condensed"
            android:gravity="bottom"
            android:padding="5sp"
            android:text="Ambient screen reduces battery life."
            android:textSize="16sp" />

        <TextView
            android:id="@+id/tv_question"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-condensed"
            android:gravity="center_horizontal|top"
            android:paddingBottom="15sp"
            android:paddingTop="5sp"
            android:text="Turn on?"
            android:textSize="18sp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5sp">

            <android.support.wearable.view.CircledImageView
                android:id="@+id/btn_cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|bottom"
                android:src="@drawable/ic_cross"
                app:circle_color="#AFAFAF"
                app:circle_radius="25dp"
                app:circle_radius_pressed="20dp" />

            <android.support.wearable.view.CircledImageView
                android:id="@+id/btn_ok"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|bottom"
                android:src="@drawable/ic_tick"
                app:circle_color="#0EB695"
                app:circle_radius="25dp"
                app:circle_radius_pressed="20dp" />
        </FrameLayout>
    </LinearLayout>
</android.support.wearable.view.BoxInsetLayout>

它看起来像设置中的确认屏幕.也许它仍然需要一些调整,但是我认为这是要走的路.

It looks just like the confirmation screen from the settings. Maybe it still needs some tweaks, but I think this is the way to go.

这篇关于显示Android Wear样式AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆