我想应用一种样式,如 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://daniel-codes.blogspot.com/2011/08/new-to-android-more-style-restrictions.html
最佳答案
最后我用 Dialog
而不是 DialogFragment
解决了这个问题,因为最后一个不支持透明布局。很容易设置透明背景制作一个新的 activity
并在 Manifest
中设置样式。否则我不得不使用 Activity 而不是 fragment 来更改对话框的结构。
我希望这可以节省一些人的研究时间。
再见!
关于android - 使用私有(private)样式(找不到与给定名称匹配的资源),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13655909/