i want to open twitter auth in my webview rather then opening in browser, any good tutorial how to play with webview in dialog and loading it inside dialog?
Asked
Active
Viewed 1.4k times
3 Answers
6
You can just apply dialog theme to regular activity which contains a WebView.

Konstantin Burov
- 68,980
- 16
- 115
- 93
-
i am having problem with that. i am using browser type of application and once i complete the Authorizing App. It does not redirect me to my webpage. Instead i shows me redirect but it remains on the same page. Any idea how to deal with such problem? – insomiac Jun 01 '11 at 19:46
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();

Pointer Null
- 39,597
- 13
- 90
- 111
1
Open like dialog and register in Manifest.xml file. Use like Dialog box.
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();
}
}
}

Jeremy Wiebe
- 3,894
- 22
- 31

Ashok Domadiya
- 1,124
- 13
- 31