使用私有样式(找不到与给定名称匹配的资源)

时间:2012-12-01 02:57:41

标签: android android-layout android-resources android-theme android-styles

我想将Graphical Layout节目的样式应用为Theme.DeviceDefault.Dialog.Alert。我知道现在这是一种私人风格,我不能把它作为父母。

如何将这种风格发送到我的DialogFragment

(我的目标是API 15,也许我想使用minSdk API 12。)

这报告了一个错误(父母,就像我读过,现在是私人的):

<style name="MyDialogStyle" parent="@android:style/Theme.DeviceDefault.Dialog.Alert">
  

找不到与给定名称匹配的资源。

我刚看过我必须“复制”款式,但我找不到它的位置?

是的,有人可以帮帮我吗?我需要将该样式“克隆”为我的自定义样式。

提前致谢。

我尝试过的事情:

DialogFragment的硬编码背景

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));

    return super.onCreateView(inflater, container, savedInstanceState);
}

我的自定义风格

<style name="MyDialogStyle">    
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

我访问过这些链接:

http://developer.android.com/reference/android/app/AlertDialog.html http://developer.android.com/guide/topics/ui/themes.html

http://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=18659

No resource found that matches the given name '@android:style/AlertDialog' error after the latest android 3.2 sdk update

http://daniel-codes.blogspot.com/2011/08/new-to-android-more-style-restrictions.html

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

https://android.googlesource.com/platform/frameworks/base/+/d11e6151fe88314505fa7adca6278de2e772b11c/core/res/res/values/themes_device_defaults.xml

1 个答案:

答案 0 :(得分:1)

最后,我使用Dialog而不是DialogFragment解决了这个问题,因为最后一个不支持透明度布局。设置透明背景很容易设置新activity并在Manifest中设置样式。否则,我不得不使用活动而不是片段来更改对话框的结构。

我希望这能为他们节省数小时的研究时间。

再见!