Android Dialog弹窗提示,在4.4.4和5.1中会默认显示Dialog的title

来源:互联网 发布:中科软件怎么样 编辑:程序博客网 时间:2024/06/05 14:46

在项目中fragment用到Dialog做一个不带标题的提示,准确讲是一个功能的使用说明。在4.4.4和5.1中会默认显示空白title。

 private void showProduceDialog() {              Dialog dialog = new Dialog(getContext());        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题        dialog.getWindow().setBackgroundDrawableResource(R.drawable.produce_backgroud);        View view = getActivity().getLayoutInflater().inflate(R.layout.produce_dialog_layout, null);        dialog.setContentView(view);        final TextView tvTitle = (TextView) view.findViewById(R.id.produce_content);                tvTitle.setText(R.string.vibration_indroduce_text);            Window dialogWindow = dialog.getWindow();        WindowManager.LayoutParams lp = dialogWindow.getAttributes();        dialogWindow.setGravity(Gravity.CENTER )        /*         * 将对话框的大小按屏幕大小的百分比设置         */        WindowManager m = getActivity().getWindowManager();        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值        p.height = (int) (d.getHeight() * 0.45); // 高度设置为屏幕的0.6        p.width = (int) (d.getWidth() * 0.6); // 宽度设置为屏幕的0.65        dialogWindow.setAttributes(p);        dialog.show();    }
//添加到Dialog的布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <ScrollView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:paddingTop="5dp"        android:paddingBottom="5dp">    <TextView        android:id="@+id/produce_content"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:paddingLeft="5dp"        android:textSize="14sp"        android:paddingRight="5dp"/>    </ScrollView></LinearLayout>


阅读全文
0 0
原创粉丝点击