其他注意事项:
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;
}
}
打赏
微信扫一扫,打赏作者吧~