在DialogFragment的标题内放置一个按钮 [英] Place a button inside DialogFragment's title

查看:103
本文介绍了在DialogFragment的标题内放置一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示了另一个DialogFragmentDialogFragment.我需要在其旁边设置标题和一个按钮.我不想重新实现主题并在DialogFragment的内容视图中创建自定义视图,而不是对话框标题(因为它容易出错并且浪费时间).可能吗?我尝试了许多API函数,例如AlertBuilderActionBar,仍然找不到符合我需要的内容.

I show a DialogFragment from another DialogFragment. I need to set title and a button just next to it. I don't want to reimplement the theme and create a custom view inside DialogFragment's content view instead of dialog title (because it's error-prone and time wasting). Is it even possible? I tried many API functions, AlertBuilder, ActionBar, this and that, still didn't found anything that fits my needs.

推荐答案

尝试如下操作:

// Title
final int titleId = getResources().getIdentifier("alertTitle","id","android");
TextView title = (TextView) popup.findViewById(titleId);
title.setText("My new title");

// Title's parent layout
ViewGroup viewGroup = (ViewGroup) title.getRootView();

// Button
Button button = new Button(this);
button.setText("A Button");
viewGroup.addView(button);

注意:您可能需要调整buttontitle对象的LayoutParams.

Note: You may need to adjust the button and title objects' LayoutParams.

这篇关于在DialogFragment的标题内放置一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆