我希望进一步自定义我的DialogFragment,特别是我希望更改DialogFragment标题的字体和字体颜色。另外,我想在标题和DialogFragment的其余部分之间自定义分隔线/蓝线。
到目前为止,我已成功使用onCreateView为进入DialogFragment的主要内容构建自定义布局。我的DialogFragment可以在下面看到XML进一步向下。
关于如何执行上述自定义的任何想法?
DialogFragment代码:
public class DialogFragmentFincCalctrInfo extends DialogFragment {
public String TAG = "DialogFragmentFincCalctrInfo";
public MainActivity mainActivity;
public Display display;
public Typeface officialBoldFont, officialRegularFont;
public TextView tvFincCalctrInfo, tvDialogFragmentFincCalctrInfoTitle;
//!< FincCalctr fragment constructor
public DialogFragmentFincCalctrInfo () {
}
//!< FincCalctr fragment constructor
public DialogFragmentFincCalctrInfo(MainActivity _mainActivity, Display _display) {
mainActivity = _mainActivity;
display = _display;
}
//!< Inflate and customise the fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getDialog().setTitle(R.string.finc_calc_info_heading);
officialRegularFont = Typeface.createFromAsset(getActivity().getAssets(), "square721extendedreg.ttf");
officialBoldFont = Typeface.createFromAsset(getActivity().getAssets(), "square721extendedbold.ttf");
Log.w(TAG, "- - - Main RL - - -");
View rlMain = inflater.inflate(R.layout.dialog_fragment_layout_finccalctr_info, container, false);
//
tvFincCalctrInfo = (TextView) rlMain.findViewById(R.id.tv_finccalctr_info);
tvFincCalctrInfo.setTextSize(14.5f);
tvFincCalctrInfo.setTypeface(officialRegularFont);
tvFincCalctrInfo.setText(R.string.finc_calc_info_bullet_points_first_pgraph);
tvFincCalctrInfo.setGravity(Gravity.CENTER_VERTICAL);
tvFincCalctrInfo.setTextColor(Color.parseColor("#000000"));
return rlMain;
}
}
XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">
<ScrollView
android:id="@+id/sv_finccalctr_infolayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/ll_sv_finccalctr_infolayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_finccalctr_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
谢谢!!!
答案 0 :(得分:0)
我将ScrollView实现到我自己的对话框设计中。改变了一些事情,但我认为它仍然应该正确模仿默认的android对话框。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:gravity="center_vertical"
android:textColor="#28B0DF"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="35dp"
android:textSize="20sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"/>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#28B0DF"/>
<ScrollView
android:id="@+id/sv_finccalctr_infolayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/ll_sv_finccalctr_infolayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_finccalctr_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
要使用此布局,只需将其设置为对话框:
dialog.setContentView(R.layout.dialog_layout);
这可以在onCreateView
或onCreateDialog
完成。