具有默认对话框外观和感觉的自定义对话框 - 这可能吗?
澄清:我希望所有自定义对话框看起来像系统默认对话框:例如,当用户使用 htc sense 时,对话框应匹配 htc sense 对话框样式,当用户使用三星官方自定义对话框时,对话框应该看起来像这样。我想尽可能地本土化。我知道可以修改对话框,但我正在寻找一种方法来引用系统使用的样式并用它创建对话框。
我拥有的:
我想要实现的目标:< /strong>
我用 dialog.setContentView(... 调用的对话框布局代码)
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Theme.Dialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
</ListView>
</LinearLayout>
如您所见,设置style="@android:style/Theme.Dialog
没有帮助。有什么想法可能有帮助吗?
(我很熟悉已经有这样一个问题:https://stackoverflow.com/questions/6746535/ android-custom-dialog-but-with-look-and-feel-of-default-one 但没有可接受的答案)
For clarification: I want all the custom dialogs to look like system default dialogs: for example, when user is using htc sense, the dialog should match htc sense dialog style, when user is using samsung with official customasation, the dialog should look like it. I want to go as native as possible. I am familiar that there are possibilities to modify the dialog, but I'm looking for a way to reference to the style the system uses and create a dialog with that.
What I have:
What I would like to achieve:
Code for my dialog layout which I invoke with dialog.setContentView(...)
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Theme.Dialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
</ListView>
</LinearLayout>
As you can see setting the style="@android:style/Theme.Dialog
isn't helping. Any ideas what might be helping?
(I am familiar that there is already such a question: https://stackoverflow.com/questions/6746535/android-custom-dialog-but-with-look-and-feel-of-default-one but there isn't an accepted answer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望出现的对话框仅用于您的应用程序目的,请按照以下步骤操作:
查看此图像,我已创建此图像以保存图像或将其发布到其他方式。
我已根据我的要求创建了 xml 布局。如果您想添加问题中所解释的列表视图,那么您必须在对话框的内容中手动实现该行为。这种布局的方法您必须实现具有该单选按钮和文本的自定义 ListView。并且还有一些 Java 代码根据该选择执行操作。
有了它,您就可以实现您想要的目标。
享受。 :)
If you want the dialog that appear just for your application purpose then follow this:
See this image i have create this one to save Image or Post it to different way.
I have created the xml layout as per my requirement. If you want to add the list view as you have explained in to the question then you have to manualy implement that behaviour in the content of the dialog. Means for such layour You have to implement the Custom ListView that have that radio button and text. And also have some Java code to do action according to that selection.
With that you can acheive as you want.
Enjoy. :)
您可以为 一个 UI 构建一个看起来像本机的对话框,但是当另一个用户有其他 ROM/修改过的 UI 时,那么该对话框看起来不像本机对话框。没有内置功能来访问系统对话框资源并仅从本机布局填充所有对话框。
You can build a native-look like dialog for one UI, but when another user has some other ROM/modified UI, then the dialog doesn't look like a native one to hem/her. There isn't a built in functionality, to access system dialog resources and populate all dialogs from native layouts only.