【问题标题】:Is it possible to style AlertDialog independently of activity's theme?是否可以独立于活动主题设置 AlertDialog 样式?
【发布时间】:2013-01-24 12:10:37
【问题描述】:

我意识到这个问题有点奇怪,但我想停止使用已弃用的选项菜单并切换到操作栏。不幸的是,为此我必须使用 Holo 主题,它带有与以前不同的 AlertDialog 设计。

这个新设计打破了我的 UI 外观。是否可以在 Holo 风格的 Activity 中创建旧式对话框?

相关问题:除了 AlertDialog 之外,还有什么可以显示我自己的布局的弹出窗口,并且在我的自定义布局周围没有边框和其他主题定义的东西?

【问题讨论】:

  • 哪个是您在清单中设置的 minimumSdkversion,哪个是 targetSdkVersion?
  • @Android-Developer: min 是 12,目标曾经是 10 以使菜单可用,现在我想将其设置为至少 14。刚刚测试时是 17 .
  • 您可以将自定义布局用作警报对话框
  • @AmitHooda:我就是这么做的,但是 Holo 中的 AlertDialog 有一个粗边框,我需要去掉。

标签: android user-interface dialog android-alertdialog


【解决方案1】:

根据您在 AndroidManifest 文件中设置的 minSDKVersion,您可以为对话框选择主题。您可以将它们设置为 Holo / Device Default,但要做到这一点,您的 minSdk 值应该是 10+,即使我认为使用 DeviceDefault 它应该是 JellyBean。

如果您想创建自己的布局并使用它而没有任何边框等会破坏您的设计,您应该使用 Dialog 而不是 AlertDialog 并对其进行自定义。你可以这样做:

final Dialog alert = new Dialog(FingerPaintActivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE); // no title 
alert.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; // this is used for custom animation when dialog is showing and hiding 
alert.setContentView(getLayoutInflater().inflate(R.layout.stamps, null)); // here is your custom layout
alert.getWindow().setLayout(width-50, (height-100)); // set height / width

当你想在你的按钮中触发 onlclick 时,例如,它位于 R.layout.stamps 中,如示例中所示,你应该这样做:

Button dog = (Button) alert.findViewById(R.id.dog_stamp);

【讨论】:

    【解决方案2】:

    您可以创建自定义AlertDialog

    例如:http://www.mkyong.com/android/android-custom-dialog-example/

    【讨论】:

    • 但我想要相反,除非我错过了有关该项目的某些内容
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多