我想用文本消息显示弹出对话框,但格式不起作用。
我希望它位于弹出窗口的中心并使用特定的字体,但都不适用。
我的代码:警报对话框中的TextView未居中或格式化
AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = LayoutInflater.from(mContext).inflate(R.layout.my_view, null);
dialog.setView(view);
TextView messageView = (TextView) view.findViewById(R.id.message);
messageView.setTextIsSelectable(true);
messageView.setText("This is the message to show");
dialog.show();
而且布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal"
android:background="@color/red"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textSize="14sp"/>
</LinearLayout>
有什么问题吗?
textview的引力怎么样? –
@AmitVaghela:我也尝试过重力和布局重心。不起作用 – Jim
请检查我的答案,并询问我是否有任何疑问 –