我有一个DialogFragment
包含一个WebView
. 我在活动中创建一个实例DialogFragment
并调用show
它的方法。通常这会将其显示为Dialog
活动的当前视图,但随机它会全屏显示,就好像我调用了该setContentView
方法一样。这是活动中的代码:
InternetDialog webDialog = new InternetDialog();
webDialog.setUrl(mRequestToken.getAuthenticationURL());
webDialog.show(getSupportFragmentManager(), "Twitter WebView");
WhereInternetDialog
是一个在方法内扩展DialogFragment
和创建的类。我正在使用旧 Android 操作系统版本的支持库。所以,我的问题是:为什么显示全屏不是对话框?View
onCreateDialog
DialogFragment
编辑:这是InternetDialog
该类的代码:
public class InternetDialog extends DialogFragment{//the soft keyboard won't show up
private String url;
WebView webView;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = LayoutInflater.from(getActivity());
View v = inflater.inflate(R.layout.internet_dialog, null);
WebView web = (WebView) v.findViewById(R.id.web);
EditText edit = (EditText) v.findViewById(R.id.edit);
edit.setFocusable(true);
edit.requestFocus();
web.loadUrl(url);
this.webView = web;
builder.setView(v);
return builder.create();
}//end of onCreateDialog() method
public View getWebView(){
return webView;
}
public String getUrl(){
return this.url;
}//end of getUrl() method
public void setUrl(String url){
this.url = url;
}//end of setUrl() method
}//end of DialogFragment class
这是internet_dialog
XML
文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:visibility="invisible"/>
<WebView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>