Android Dialog彈窗提示,在4.4.4和5.1中會默認顯示Dialog的title

在項目中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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章