【问题标题】:setTitle of DialogFragment not working in Android MDialogFragment 的 setTitle 在 Android M 中不起作用
【发布时间】:2016-07-05 06:37:16
【问题描述】:

我正在尝试将标题设置为 DialogFragment,它在 android M 下运行良好,但在 M 中却不行。

提前致谢。

【问题讨论】:

  • 是的..但我在那里没有发现任何有用的东西。
  • 可能你的标题文字颜色和标题背景颜色一样,换个颜色试试
  • Android M 及以上的对话框没有标题框。最好使用 TextView 作为自定义标题框为 Devices Marshmallow 及更高版本创建一种不同的布局。
  • @MohammedAtif 这个信息可以在 Android 文档的某个地方找到吗?

标签: android dialog android-6.0-marshmallow android-dialogfragment


【解决方案1】:
final AlertDialog diag = new AlertDialog.Builder(this)
    .setTitle("Enter An Administrative Password")
    .setView(R.layout.admin_password_dialog)
    .create();

diag.show();

Button diagButton = (Button) diag.findViewById(R.id.btn_confirmPassword);
diagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
    // handle button click
    EditText input = (EditText) diag.findViewById(R.id.edit_adminPassword);
    String s = input.getText().toString();
}
});

【讨论】:

  • 谢谢。但我也试过这个。。还是不行。
  • 试试这个@style/Theme.AppCompat.Light.Dialog.Alert
  • 我正在使用 DialogFragment 来显示警报..bcoz 我必须进行 API 调用并且全部在 Dialog 中...所以请帮助我使用 DialogFragment 解决这个问题。
【解决方案2】:

您也可以尝试构建自己的自定义外观对话框:

new AlertDialog.Builder(new ContextThemeWrapper(Context, R.style.customDialog))
            .setTitle("Title")
            .setMessage("Some message").show();

**In your style:**
<style name="customDialog">
    <item name="android:textColor">@color/txt_color</item>
</style>

**In your colors:**
<color name="txt_color">#ff96f3</color>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多