您的位置:首页 > 移动开发 > Android开发

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

2017-09-14 12:44 603 查看
在项目中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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: