在DialogFragment的标题内放置一个按钮 [英] Place a button inside DialogFragment's title
问题描述
我显示了另一个DialogFragment
的DialogFragment
.我需要在其旁边设置标题和一个按钮.我不想重新实现主题并在DialogFragment
的内容视图中创建自定义视图,而不是对话框标题(因为它容易出错并且浪费时间).可能吗?我尝试了许多API函数,例如AlertBuilder
,ActionBar
,仍然找不到符合我需要的内容.
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);
注意:您可能需要调整button
和title
对象的LayoutParams
.
Note: You may need to adjust the button
and title
objects' LayoutParams
.
这篇关于在DialogFragment的标题内放置一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!