我想在我的webview中打開twitter auth,而不是在瀏覽器中打開,任何好的教程如何在對話框中使用webview並在對話框中加載它?android在對話框中加載webview
2
A
回答
6
您可以將對話主題應用於包含WebView的常規活動。
5
Context mContext = this;
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle("Riga");
WebView wv = new WebView(mContext);
String html = "<html><body>some html here</body></html>";
wv.loadData(html, "text/html", "UTF-8");
alert.setView(wv);
alert.setIcon(R.drawable.icon);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Toast.makeText(getApplicationContext(), "Fail", Toast.LENGTH_SHORT).show();
}
});
alert.show();
0
打開像對話框並在Menifeast.xml文件中註冊。使用像對話框一樣。
public class WebDialog extends Dialog
{
static final int BLUE = 0xFF6D84B4;
static final float[] DIMENSIONS_DIFF_LANDSCAPE =
{ 20, 60 };
static final float[] DIMENSIONS_DIFF_PORTRAIT =
{ 40, 60 };
static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
static final int MARGIN = 4;
static final int PADDING = 2;
static final String DISPLAY_STRING = "touch";
private String mUrl;
// private DialogListener mListener;
private ProgressDialog mSpinner;
private WebView mWebView;
private LinearLayout mContent;
private TextView mTitle;
public WebDialog(Context context, String url)
{
super(context);
mUrl = url;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mSpinner = new ProgressDialog(getContext());
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");
mContent = new LinearLayout(getContext());
mContent.setOrientation(LinearLayout.VERTICAL);
setUpTitle();
setUpWebView();
Display display = getWindow().getWindowManager().getDefaultDisplay();
final float scale = getContext().getResources().getDisplayMetrics().density;
int orientation = getContext().getResources().getConfiguration().orientation;
float[] dimensions = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? DIMENSIONS_DIFF_LANDSCAPE : DIMENSIONS_DIFF_PORTRAIT;
addContentView(mContent, new LinearLayout.LayoutParams(display.getWidth() - ((int) (dimensions[0] * scale + 0.5f)), display.getHeight() - ((int) (dimensions[1] * scale + 0.5f))));
}
private void setUpTitle()
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable icon = getContext().getResources().getDrawable(R.drawable.ic_launcher);
mTitle = new TextView(getContext());
mTitle.setText("Website");
mTitle.setTextColor(Color.WHITE);
mTitle.setTypeface(Typeface.DEFAULT_BOLD);
mTitle.setBackgroundColor(BLUE);
mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
// mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
// mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
mContent.addView(mTitle);
}
private void setUpWebView()
{
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new WebDialog.DialogWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
System.out.println(" mURL = "+mUrl);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
mContent.addView(mWebView);
}
private class DialogWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
super.onReceivedError(view, errorCode, description, failingUrl);
WebDialog.this.dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
mSpinner.show();
}
@Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
String title = mWebView.getTitle();
if (title != null && title.length() > 0)
{
mTitle.setText(title);
}
mSpinner.dismiss();
}
}
}
相關問題
- 1. Android的webview加載對話框
- 2. Webview加載對話框
- 3. 在android中的對話框中加載webview時獲取void android.webkit.WebView.loadUrl?
- 4. 在android中加載對話框
- 5. 在android中加載對話框
- 6. Android - Webview在彈出對話框中?
- 7. Android加載對話框Freez
- 8. 在webview中添加進度對話框
- 9. 點擊Webview加載的Android進度對話框 - 空白屏幕
- 10. Android - 在webview中加載PDF
- 11. 對話框中的WebView
- 12. 如何將加載器對話框添加到我的webview?
- 13. Android:加載活動對話框
- 14. Android自定義進度對話框webview
- 15. 顯示加載對話框,直到網頁完全加載到WebView中
- 16. ember.js在對話框中加載數據
- 17. 在BackgroundWorker中加載對話框
- 18. 在對話框中的Cordova WebView
- 19. 在Android 4.0中隱藏對話框中的軟鍵盤加載
- 20. 如何在android中的自定義對話框中顯示webview?
- 21. WebView加載頁面時的進度對話框
- 22. 加載對話框預加載頁面
- 23. jquery對話框ajax加載
- 24. jquery對話框加載器
- 25. 加載對話框BlackBerry Browserfield
- 26. 如何在android中加載進度對話框?
- 27. 在Android中運行方法時顯示加載對話框?
- 28. 在Android中加載數據庫時顯示進度對話框
- 29. 如何在android中顯示「加載...」對話框?
- 30. 如何從對話框中重新加載jQuery對話框?
我有問題。我正在使用瀏覽器類型的應用程序,一旦我完成授權應用程序。它不會將我重定向到我的網頁。相反,我顯示我重定向,但它仍然在同一頁面上。任何想法如何處理這樣的問題? – insomiac 2011-06-01 19:46:32