2017-08-30 353 views
0

我試圖使類似於此的對話框:用標題創建全屏對話框和取消/ OK按鈕

Costum full screen dialog example

但無論是Android開發者指南,也沒有見到能解決我的問題問題:

  1. 標題不顯示,我只是得到我的服裝佈局。

  2. 我不知道如何在左邊放一個「x」,在右邊放一個保存圖標!它應該與WINDOW FEATURES一起使用嗎?

的dialogfragment代碼:

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.dialogfragment_statsentry, container, false); 
} 

@NonNull 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    Dialog mDialog = super.onCreateDialog(savedInstanceState); 
    mDialog.setTitle("hello"); 
    return mDialog; 
} 

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
} 

的dialogfragment XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:minWidth="600dp" 
    android:layout_height="match_parent" 
    android:minHeight="400dp" 
    android:orientation="vertical" 
    android:padding="10dp"> 

    <TextView 
     android:id="@+id/dialog_statsentry_txvTime" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.TextInputEditText 
      android:id="@+id/dialog_statsentry_edtName" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" /> 
    </android.support.design.widget.TextInputLayout> 

</LinearLayout> 

我如何調用對話框:

StatsEntryFragmentDialog mFragment = new StatsEntryFragmentDialog(); 

FragmentManager mManager = getSupportFragmentManager(); 

if (Utils.isTablet(getApplicationContext())) { 
    mFragment.show(mManager, mFragment.TAG); // no fullscreen for bigger displays 
} 
else { 
    FragmentTransaction mTransaction = mManager.beginTransaction(); 
    mTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 

    mTransaction.add(CONTENT_CONTAINER, mFragment).addToBackStack(mFragment.TAG).commit(); 
} 

提前感謝!

+0

它也更好窗口開始對話主題活動。 – Piyush

+0

我不知道你的意思? –

+0

請參閱此鏈接https://stackoverflow.com/questions/18315343/android-make-a-dialog-appear-in-fullscreen –

回答

2

試試你的對話框的這套HIGHT和寬度編程方式使用像下面的代碼

Window window = customDialog.getWindow(); 
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); 
window.setGravity(Gravity.CENTER); 
customDialog.show(); 
+0

這應該解決哪個問題? –

+0

謝謝,但那不是我的問題?請在問題中閱讀我的兩個要點! –