Showing posts with label Transparent. Show all posts
Showing posts with label Transparent. Show all posts

Friday, April 13, 2012

Android: How to refresh on transparent background webview?

If you set Webview's background to be transparent, then whenever you load a new page, contents will overlap.

To solve this issue:


       webView.clearView();
       webView.loadUrl(url);

Clear view before you load something else.

Thursday, April 12, 2012

Android Webview with transparent background

Yes, it is possible!

           webView.setBackgroundColor(0x00FFFFFF);

However, if in your AndroidManifest.xml contains:

             android:hardwareAccelerated="true"
webView's background, for some reason, does not change to transparency.
(It took me while to figure this out!)

This is how to disable hardware acceleration on the view that contains webview:

             view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Monday, April 9, 2012

Android Dialog with transparent background

This is an example of when an Activity is set as Dialog style:

Ex:
AndroidManifest.xml:

        <activity
            android:theme="@android:style/Theme.Holo.Light.Dialog.MinWidth"
            android:name=".DialogActivity" />

Different Dialog styles are:
- android:theme="@android:style/Theme.Dialog"
- android:theme="@android:style/Theme.Holo.Dialog"
- android:theme="@android:style/Theme.Holo.Dialog.MinWidth"
- android:theme="@android:style/Theme.Holo.Dialog.NoActionBar"
- android:theme="@android:style/Theme.Holo.Dialog.NoActionBar.MinWidth"
- android:theme="@android:style/Theme.Holo.DialogWhenLarge"
- android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar"
- android:theme="@android:style/Theme.Holo.Light.Dialog"
- android:theme="@android:style/Theme.Holo.Light.Dialog.MinWidth"
- android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar"
- android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth"
- android:theme="@android:style/Theme.Holo.Light.DialogWhenLarge"
- android:theme="@android:style/Theme.Holo.Light.DialogWhenLarge.NoActionBar"

DialogActivity.java:

       @Override
       protected void onCreate(Bundle savedInstanceState){
             super.onCreate(savedInstanceState);
             requestWindowFeature(Window.FEATURE_NO_TITLE);
             getWindow().setBackgroundDrawable(new ColorDrawable(0));
             setContentView(R.layout.main);
       }

-------------------------------------

OR:

Dialog:


             final Dialog dialog = new Dialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth);
             dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
             dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
             dialog.setContentView(R.layout.main);
             dialog.setCancelable(true);
             dialog.show();