android fragment 弹出对话框,Android中使用Dialogfragment显示对话框
其他注意事項:
1、如何設置自己的Dialogfragment沒有標題欄?
可以通過兩種方法來設置 ,一種是使用dialogfragment的setStyle函數,另外就是使用getDialog().getWindow().requestFeature方法,具體代碼如下
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//如果要使用此方法,則必須將代碼放到onCreateDialog中,因為一旦其中的dialog創建成功后,setStyle將不再起作用
setStyle(STYLE_NO_TITLE, 0);
return super.onCreateDialog(savedInstanceState);
}
1
2
3
4
5
6
@Override
publicDialogonCreateDialog(BundlesavedInstanceState){
//如果要使用此方法,則必須將代碼放到onCreateDialog中,因為一旦其中的dialog創建成功后,setStyle將不再起作用
setStyle(STYLE_NO_TITLE,0);
returnsuper.onCreateDialog(savedInstanceState);
}
使用getDialog的方法
Java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
dlgView = inflater.inflate(R.layout.add_customer_activiey, container);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dlgView;
}
1
2
3
4
5
6
7
8
9
10
@Override
publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,
BundlesavedInstanceState){
dlgView=inflater.inflate(R.layout.add_customer_activiey,container);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
returndlgView;
}
2.?The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)
此問題常是由于你所自定義的DialogFragment子類繼承自android.app.dialogfragment,而非繼承自android.support.v4.app.DialogFragment,解決辦法就是將你的自定義的DialogFragment子類繼承自android.support.v4.app.DialogFragment。如下所示:
package com.bcoder.demos;
import android.annotation.SuppressLint;
import android.support.v4.app.DialogFragment; //import這個類
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@SuppressLint("NewApi")
public class AddSubClassDialog extends DialogFragment {
View addview = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
addview = inflater.inflate(R.layout.add_sub_class, container);
return addview;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
packagecom.bcoder.demos;
importandroid.annotation.SuppressLint;
importandroid.support.v4.app.DialogFragment;//import這個類
importandroid.support.v4.app.Fragment;
importandroid.os.Bundle;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
@SuppressLint("NewApi")
publicclassAddSubClassDialogextendsDialogFragment{
Viewaddview=null;
@Override
publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,
BundlesavedInstanceState){
addview=inflater.inflate(R.layout.add_sub_class,container);
returnaddview;
}
}
打賞
微信掃一掃,打賞作者吧~
總結
以上是生活随笔為你收集整理的android fragment 弹出对话框,Android中使用Dialogfragment显示对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几张一模一样的照片_两张一模一样的照片看
- 下一篇: android广播注册源码,androi