1

我有一个DialogFragment包含一个WebView. 我在活动中创建一个实例DialogFragment并调用show它的方法。通常这会将其显示为Dialog活动的当前视图,但随机它会全屏显示,就好像我调用了该setContentView方法一样。这是活动中的代码:

    InternetDialog webDialog = new InternetDialog();
    webDialog.setUrl(mRequestToken.getAuthenticationURL());
    webDialog.show(getSupportFragmentManager(), "Twitter WebView");

WhereInternetDialog是一个在方法内扩展DialogFragment和创建的类。我正在使用旧 Android 操作系统版本的支持库。所以,我的问题是:为什么显示全屏不是对话框?ViewonCreateDialogDialogFragment

编辑:这是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>
4

1 回答 1

0

这更适合作为评论,但我还不能发表评论……您是否考虑过查看您对setStylein的电话onCreate?从文档的外观来看,当您设置对话框的样式时,STYLE_NO_FRAME 可能会干扰窗口大小,因为生成的视图完全取决于onCreateView.

于 2013-05-17T21:04:24.283 回答