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

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

我想应用一种样式,如 Graphical Layout 显示为 Theme.DeviceDefault.Dialog.Alert。我知道现在是私有(private)风格,我不能把它当作 parent 。

我该怎么做才能使我的 DialogFragment 具有这种样式?

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

这向我报告了一个错误(正如我所读,父级现在是私有(private)的):

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

No resource found that matches the given name.

我刚刚看到我必须“复制”样式项,但我找不到它在哪里?

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

提前致谢。

我尝试过的事情:

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

最佳答案

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

我希望这可以节省一些人的研究时间。

再见!

关于android - 使用私有(private)样式(找不到与给定名称匹配的资源),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13655909/

相关文章:

android - 无法将 Android 应用程序从 Eclipse 下载到我的设备

android - 在 android 中调用号码的隐式 Intent - ACTION_DIAL 和 ACTION_CALL

android - 错误 : package com. bumptech.glide.request.animation 不存在

android - 如何通过将字符串值与图像名称匹配来选择可绘制图像?

android - onTouchevent() 与 onTouch()

Android 首次打开应用程序时的说明?

android - 回收器 View 下方有按钮,布局崩溃

android - 在 LinearLayout 中重叠 TextView

android - 如何将obtainStyledAttributes(int []) 与Android 的内部主题一起使用

android-resources - 链接文件资源失败