Monday, July 15, 2013

Custom Android Dialog Without Title

I searched a lot for creating android custom dialog without title. At last i found the following. Create custom android dialog without title in the following way.

Step-1: Add a android style in style.xml file :
          <style name="TitleLessDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
 </style>

Step-2: While declaring the dialog in your activity file declare as following

.
import android.app.Dialog;

import android.content.Context;
.
.
Context context = this;
Dialog dialog = new Dialog(context,R.style.TitleLessDialog);
.
.
.


The rest of your code is as usual Dialog building code.

Thank you.
bodhisattwa

Creating Android Custom TextView Rounded Corner Programmatically

To create a rounded corner custom TextView in your android application, follow the below steps.


Step-1: Create a custom xml file named "custom_shape.xml" under /res/drawable folder.

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle"> 
 <gradient  
     android:angle="270"/>
<corners 
     android:bottomRightRadius="7dp" 
     android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp"/> 
  <solid android:color="@android:color/transparent"/>  
  <stroke 
      android:color="@android:color/black"
      android:width="5sp"/> 
</shape> 

Step-2: Create a custom TextView class "TextViewOutLined.java"

public class TextViewOutLined extends TextView
{
public static int textSize = 30;  //The size of the text can be changed later
public TextViewOutLined(Context context) 
{  
super(context); 
init(); 
}
@Override   
 protected void onDraw(Canvas canvas) {  
super.onDraw(canvas);                 
this.setBackgroundResource(R.drawable.custom_shape);    
} 
private void init(){  
setTextSize(textSize);  
setPadding(5, 5, 5, 5);  //This will set the padding, and by increasing decreasing this 
// parameters the text padding can be changed 
}
}

Step-3: Use the class TextViewOutLined in your android program as:
private final TextViewOutLined tv = new TextViewOutLined(context);
tv.setText("www.appsoid.in");

Thank you.
bodhisattwa