我需要将字体更改为我的alertDialog(资产文件夹中存在自定义字体),在对话框中我有按钮,(正面和负面),以及要检查的项目,如何将字体更改为所有元素我的对话? 我在代码中创建对话框,它不是带有xml的自定义对话框;
谢谢你!答案 0 :(得分:0)
public class ApproveDialog extends DialogFragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.custom_dialog, container, false); TextView styleText=(TextView)v.findViewById(R.id.styleText); Typdface tf=Typeface.createFromAsset(getResources().getAssets(),"abc.ttf"); styleText.setTypeface(tf); return v; } }
FragmentTransaction ft=getActivity().getSupportFragmentManager().beginTransaction(); Fragment prev = getActivity().getSupportFragmentManager().findFragmentByTag("dialog1"); if (prev != null) ft.remove(prev); ft.addToBackStack(null); // Create and show the dialog. ApproveDialog newFragment = new ApproveDialog(); newFragment.show(ft, "dialog");
<TextView id="@+id/styleText">
答案 1 :(得分:0)
要更改对话系统,可以使用以下代码。您可以使用警报构建器来构建警报。然后,您可以从此警报中获取TextView和EditView,然后设置警报的字体。
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello").setTitle("Title Alert").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
Typeface face= Typeface.createFromAsset(getAssets(), "segoe.ttf");
int titleId = getResources().getIdentifier("alertTitle", "id", "android"); if (titleId > 0) {
TextView dialogTitle = (TextView) dialog.findViewById(titleId);
if (dialogTitle != null) {
dialogTitle.setTypeface(face);
}
}
textView.setTypeface(face);