Android View rounded corners

To create rounded corners in a view, first create a xml file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="15dip" />
            <solid android:color="#404f64" />
            <stroke android:width="2dp" android:color="#bebfc1"/>
        </shape>
    </item>
</layer-list>

Save the file as rounded.xml or other name in the /res/layout folder.

For android:shape you can use one of this values:
Constant Value Description
rectangle 0 Rectangle shape, with optional rounder corners.
oval 1 Oval shape.
line 2 Line shape.
ring 3 Ring shape.

After that go to the layout which you want to make with rounded corners and add this:

android:background="@layout/rounded"

And the result must be:
Rounded corners

From now on you know how to decorate your forms and application. Good luck!

Posted in Android at May 20th, 2011. 4 Comments.

Android SDK Reference Search in Chrome

One good extension for every Android developer is Android SDK Reference Search for Google Chrome browser.With this extension you can easily search in the Android SDK reference.You can download it from here Android SDK Reference Search
After install of the extension, open your Chrome browser and just type: “ad + spacebar” and you will see the result:

And voala you can easily search in Android SDK Reference through your browser. Good luck!

Posted in Android, Browsers, Chrome at March 21st, 2011. No Comments.

How-to-underline-textview-in-android

If you want to underline TextView in Android you can use this code:

        SpannableString contentUnderline = new SpannableString("some text here");
        contentUnderline.setSpan(new UnderlineSpan(), 0, contentUnderline.length(), 0);
        TextView TextViewCopyright = (TextView) findViewById(R.id.TextView01);
        TextViewCopyright.setText(contentUnderline);


Special thanks to Eli.

Posted in Android, Java at March 21st, 2011. 1 Comment.

How to show copyright symbol in textview

If you want to show copyright symbol ¬© in the TextView, you can use the Unicode character for this: “\u00A9”

    <string name="copyright">\u00A9 2011 copyright</string>

or to use ©

    <string name="copyright">&#169; 2011 copyright</string>
Posted in Android, Java at March 20th, 2011. No Comments.

Android multi line EditText

Today I will show how to create multi line EditText field in your android application.Let’s first create a EditText field:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
	<EditText
	    android:text="EditText01"
	    android:id="@+id/EditText01"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:lines="5">
	</EditText>
</LinearLayout>

Now add this android:lines=”5″

	    android:text="EditText01"
	    android:id="@+id/EditText01"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:lines="5">

And the result should be a multi line edit text.

As you can see the image the text is in the middle, let’s move it on the top of the EditText. Insert this row

android:gravity="top"

and voala, the text is on the top of the EditText.

Posted in Android, Java, Layout at March 13th, 2011. 1 Comment.

Make a button invisible or gone in an Android Application

In this post I will show you how to make button visible and invisible or gone. First let’s create three¬† buttons in our application and make them visible.
This is the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:text="Button One"
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
    <Button
        android:text="Button Two"
        android:id="@+id/Button02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
    <Button
        android:text="Button Three"
        android:id="@+id/Button03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
</LinearLayout>

Setting buttons to be visible:

package com.lardev.myButton;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button myButton1 = (Button) findViewById(R.id.Button01);
        myButton1.setVisibility(0);
        Button myButton2 = (Button) findViewById(R.id.Button02);
        myButton2.setVisibility(0);
        Button myButton3 = (Button) findViewById(R.id.Button03);
        myButton3.setVisibility(0);
    }
}

And the result is:

Now go to line 17 and change parameter from 0 to 4 and second button will be invisible when you save and start your application again, but it still takes up space in layout.

If we want to make button invisible and doesn’t take any space in the layout, then we must change parameter 8 for setVisibility method.

package com.lardev.myButton;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button myButton1 = (Button) findViewById(R.id.Button01);
        myButton1.setVisibility(0);
        Button myButton2 = (Button) findViewById(R.id.Button02);
        myButton2.setVisibility(8);
        Button myButton3 = (Button) findViewById(R.id.Button03);
        myButton3.setVisibility(0);
    }
}

And now button two is invisible and gone.Here you can see the result:

And that’s all for now, good luck

Posted in Android at February 28th, 2011. 1 Comment.

Escape ampersand in XML item array

If you want to use an ampersand as a string in item for a string-array you must escape it. It is very easy, just replace ampersand sign ( ‘&‘ ) with &amp; and save the xml layout file. Good luck.

Posted in Android at February 28th, 2011. No Comments.

How to move Android tabs from top to bottom

Today I will show how to move tabs from top to bottom of the application. This is the layout:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"
        />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:layout_alignParentBottom="true"
        />
    </RelativeLayout>
</TabHost>

And this is the Tabs class:

package com.lardev.tabs;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class Tabs extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Search.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("search").setIndicator("Search",
                          res.getDrawable(R.drawable.ic_tab_search))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Points tabs
        intent = new Intent().setClass(this, Points.class);
        spec = tabHost.newTabSpec("points").setIndicator("Points",
                          res.getDrawable(R.drawable.ic_tab_search))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Social tabs
        intent = new Intent().setClass(this, Social.class);
        spec = tabHost.newTabSpec("social").setIndicator("Social",
                          res.getDrawable(R.drawable.ic_tab_search))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Contact tabs
        intent = new Intent().setClass(this, Contact.class);
        spec = tabHost.newTabSpec("contact").setIndicator("Contact",
                          res.getDrawable(R.drawable.ic_tab_search))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

    }
}

And the result is:

Android tabs from top to bottom

More info about Tab Layout you can read from here: Tab layout read

Posted in Android at February 2nd, 2011. 2 Comments.

How to make screenshot in Android Emulator using Eclipse

There is a very easy way to make screenshot on Android Emulator using Eclipse.

  1. Click on DDMS perspective
  2. Look for Devices View, if is not visible, on the menu bar click Window > Show View > Other. In the newly opened dialog box, under Android category, select Devices.
  3. Now on the Devices View, click the button /Screen Capture/ as shown on the image and your screenshot will be ready.

Screenshot of Android Emulator

Posted in Android, Eclipse at February 1st, 2011. No Comments.