[英]How to set fontfamily in AlertDialog edittext?
I don't know how to set fontfamily for alertdialog editext.我不知道如何为 alertdialog editext 设置 fontfamily。
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Project name");
LinearLayout linearLayout = new LinearLayout(MainActivity.this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(10, 10, 10, 10);
final EditText editText = new EditText(MainActivity.this);
editText.setHint("Enter your project name");//here how to change text fontfamily
linearLayout.addView(editText);
builder.setView(linearLayout);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String text = editText.getText().toString();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
});
I tried with TypeFace but it's not working.我试过 TypeFace 但它不起作用。 if you help me then it would be great and great and i will give you one big upvote.如果你帮助我,那就太好了,我会给你一个大大的赞许。
Try using尝试使用
editText.setTypeface(
Typeface.create("serif", Typeface.NORMAL)
);
Make custom layout file for the dialog为对话框制作自定义布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Project Name"
android:fontFamily="@fonts/myFont" />
</LinearLayout>
try to these two line and check it working or not.尝试这两行并检查它是否有效。
Typeface typeface=Typeface.create("font-family",Typeface.BOLD_ITALIC);
editText.setTypeface(typeface);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.