我需要为自己的商品添加自定义标题DialogFragment
。
getDialog().setTitle("My Title");
对于我来说还不够,因为我想更改标题文本和背景颜色。
从下面的图片中可以看到,getDialog().setTitle("My Title");
我没有进行自定义(据我所知),即文本颜色为黑色,背景为白色。
我的目标是按照的要求进行My Title
定制Custom Title
。我一直在寻找API,但找不到任何将视图加载到标题部分的方法。
任何人都知道如何自定义视图或将视图设置/注入视图FragmentDialog
?
您必须通过覆盖onCreateDialog来创建自定义对话框,如下所示:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
dialogView = inflater.inflate(R.layout.dialog_change_password, null);
/* Anything that needs to be done to the view, ie.
on click listeners, postivie/negative buttons,
values being changed etc */
builder.setView(dialogView);
return builder.create();
}
和dialog_change_password.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white_grey">
<TextView
android:text="@string/change_password"
android:id="@+id/title"
style="@style/dialogHeading" />
<LinearLayout
android:layout_marginTop="10dp"
style="@style/dialogSection">
<LinearLayout
style="@style/PasswordChangeRow">
<TextView
style="@style/PasswordChangeLabel"
android:text="@string/new_password"/>
<EditText
style="@style/PasswordChangeField"
android:id="@+id/password"
android:inputType="textPassword"/>
</LinearLayout>
<LinearLayout
style="@style/PasswordChangeRow">
<TextView
style="@style/PasswordChangeLabel"
android:text="@string/confirm_password"/>
<EditText
style="@style/PasswordChangeField"
android:id="@+id/confirmPassword"
android:inputType="textPassword"/>
</LinearLayout>
</LinearLayout>
<TextView
android:text="@string/password_conditions_message"
style="@style/dialogMessage" />
</LinearLayout>
显然,xml比所需的要复杂一些,但这只是可以完成的示例,它看起来像这样
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句