ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-09 11:23:51  阅读:177  来源: 互联网

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


我想将图形布局显示的样式应用为Theme.DeviceDefault.Dialog.Alert.我知道现在这是一种私人风格,我不能把它作为父母.

如何将这种风格用于我的DialogFragment?

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

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

<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解决了这个问题,因为最后一个不支持透明度布局.很容易设置透明背景进行新活动并在Manifest中设置样式.否则,我不得不使用活动而不是片段来更改对话框的结构.

我希望这能节省许多人的研究时间.

再见!

标签:android,android-layout,android-resources,android-styles,android-theme
来源: https://codeday.me/bug/20190709/1412384.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有