android - 使用对话框主题运行 Activity

标签 android android-widget android-layout

我需要从主屏幕小部件启动一个对话框,所以我使用 android:theme="@android:style/Theme.Dialog" 创建了一个 Activity

问题是,我想让它看起来像标准对话框窗口(灰色背景上的按钮、字体和文本大小、填充等),如下所示:

alt text
(来源:android.com)

这是我的“对话”Activity 的样子:

alt text

是否有一些标准的方式(主题?)让它看起来像标准的系统对话框?还是我必须在自己的布局中模仿它?

最佳答案

您可以通过使用权重属性和按钮背后背景的可绘制框架来获得下面按钮的相同外观。希望这对您有所帮助!

             <LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:background="@android:drawable/bottom_bar"
               android:orientation="horizontal">
               <Button
                android:text="Cancel"
                android:textSize="12dip"
                android:id="@+id/cancelButton"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"/>
               <Button
                android:text="Ok"
                android:textSize="12dip"
                android:id="@+id/okButton"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"/>
           </LinearLayout>

关于android - 使用对话框主题运行 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3045406/

相关文章:

android - 无法让省略号在 Android 上工作

android - 我应该使用 RecyclerView.VERTICAL 而不是 LinearLayoutManager.VERTICAL 吗?

android - 如何在这个新的 ICS 世界中添加 UI 选项卡?

android - listview 作为 sherlock 操作栏中的操作溢出

android - Android 的“全屏”菜单

android - TextView 是 onfocus 窃取了 onclick 事件吗?

android - Activity 启动时状态栏黑色闪烁

java - 从 ListActivity 条目启动 Intent - Android

java - Android 中的倒计时器出错?

java - WebView - X 秒后加载新的 URL/文件,无限循环