WebView не отображается в AlerDialog - PullRequest
1 голос
/ 23 сентября 2011

Я пытаюсь отобразить «WebView» в «AlertDialog».Для этого я сослался на один из вопросов, размещенных здесь: Отображение WebView в AlertDialog Он успешно открывает диалоговое окно.Но я не знаю, как это не показывает веб-контент.Это мой файл 'print_webview', который я надуваю в окне AlertDialog:

'<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/root">
  <WebView
  android:id="@+id/dialog_webview"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>    
</LinearLayout>'

Это мой файл Java:

'public class CloudPrintTest extends Activity {
    static final int GOOGLE_CLOUD_PRINT_DIALOG = 1; //dialog ID for google cloud print

    /** Called when the activity is first created. */
    Button printButton;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        printButton = (Button)findViewById(R.id.button1);
        printButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //startActivity(new Intent(CloudPrintTest.this,PrintDialog.class));
                showDialog(GOOGLE_CLOUD_PRINT_DIALOG);
            }
        });
    }
    @Override
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        switch(id){
        case GOOGLE_CLOUD_PRINT_DIALOG:
            //LayoutInflater layoutInflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //final View dialogLayout = layoutInflator.inflate(R.layout.print_webview, null);
            LayoutInflater inflater = LayoutInflater.from(CloudPrintTest.this);
            View alertDialogView = inflater.inflate(R.layout.print_webview, null);
            WebView myWebView = (WebView)alertDialogView.findViewById(R.id.dialog_webview);
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            myWebView.setWebViewClient(new PrintTestWebViewClient());
            myWebView.loadUrl("http://www.google.com/");
            AlertDialog.Builder builder = new AlertDialog.Builder(CloudPrintTest.this);
            builder.setView(alertDialogView);
            builder.setTitle("Google Cloud Print");
            builder.setCancelable(true);
            AlertDialog printDialog = builder.create();
            return printDialog;
        }
        return null;
    }

    private class PrintTestWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }   
    }
}'

Я перепробовал все возможные способы, но не сделалполучить результат.Пожалуйста помоги.Привет

1 Ответ

0 голосов
/ 23 сентября 2011

То, что я хотел бы предложить, это то, что вы создаете действие.

И когда вы регистрируете его в своем манифесте.Дайте ему взгляд Диалога с

<activity android:theme="@android:style/Theme.Dialog">
...