Showing posts with label Style. Show all posts
Showing posts with label Style. Show all posts

Thursday, May 1, 2014

[Android] Set style programatically example

You can't. So there's a work around.

layout\textview_mystyle.xml
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"  
   style="@style/myStyleText"  
   android:layout_width="match_parent"  
   android:layout_height="wrap_content"  
   />  

then in your code:
 TextView tv = (TextView)getLayoutInflater().inflate(R.layout.textview_mystyle, 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();