DialogFragment在与Android的主题 [英] DialogFragment in Android with theme

查看:595
本文介绍了DialogFragment在与Android的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设我的第一个应用程序的机器人。我做了一个dial​​ogFragment,但它并不好看enough.For具有的风格和主题我用这个的setStyle(DialogFragment.STYLE_NORMAL,0)。我要的是该片段的边缘是黑色的像一帧,或有其边角圆。我想我必须写我自己的风格的XML,并把它的风格,但我不知道。有人点我到正确的方向?感谢您的时间。

I'm building my first app in android. I've made a dialogFragment, but it doesn't look nice enough.For having a style and a theme I used this setStyle(DialogFragment.STYLE_NORMAL,0). What I want is that the edge of the fragment to be black like a frame, or have its corners round. I think I must write my own style in xml and put it in styles, but I'm not sure. Can someone point me to the right direction? Thank you for your time.

推荐答案

就像你说的,你需要创建一个要应用的样式,然后将其分配给你的 DialogFragment 的setStyle()方法调用的第二个参数。你必须记住,在打电话之前,使这个电话显示()

As you say you'll need to create the style that you want to apply, and then assign it to your DialogFragment as the second parameter in the setStyle() method call. You must remember to make this call before you call show().

所以,如果你创建一个在RES /价值/ styles.xml名为myStyle的新样式:

So, if you create a new style named "MyStyle" in res/values/styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    .
    .
    .
    <style name="MyStyle">
        .
        .
        .
    </style>
    .
    .
    .
</resources>

然后用这个在你的setStyle电话:

Then use this in your setStyle call:

DialogFragment dial = (DialogFragment) Fragment.instantiate(this, MyDialogFragment.class.getCanonicalName());
dial.setStyle( DialogFragment.STYLE_NORMAL, R.style.MyStyle );
dial.show();

这篇关于DialogFragment在与Android的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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