Android中使用Dialogfragment显示对话框
					 分类:Android
阅读 (3,971)
							 Add comments
					
		4月 172013
	
其他注意事项:
1、如何设置自己的Dialogfragment没有标题栏?
可以通过两种方法来设置 ,一种是使用dialogfragment的setStyle函数,另外就是使用getDialog().getWindow().requestFeature方法,具体代码如下
| 
					 1 2 3 4 5 6  | 
							@Override 	public Dialog onCreateDialog(Bundle savedInstanceState) {                 //如果要使用此方法,则必须将代码放到onCreateDialog中,因为一旦其中的dialog创建成功后,setStyle将不再起作用 		setStyle(STYLE_NO_TITLE, 0); 		return super.onCreateDialog(savedInstanceState); 	}  | 
					
使用getDialog的方法
| 
					 1 2 3 4 5 6 7 8 9 10  | 
							@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; 	}  | 
					
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。如下所示:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  | 
						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; 	} }  | 
					

                
微信扫一扫,打赏作者吧~