Wednesday, January 12, 2011

Some Activity Style

In this article discuss some activity sytle
1. Create Title-less Activity
2. Create a Full Screen Activity

Create Title-less Activity
We can remove the title bar for every activity. The Following method used to remove the title. this method must be call before the setContentView().
requestWindowFeature(Window.FEATURE_NO_TITLE);

Sample SourceCode
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
    }
}


Create a Full Screen Activity
We can hide the title bar and windows bar. The following lines are used to hide the title and window bar

Sample SourceCode

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        Toast.makeText(this, "Welcome to Application", Toast.LENGTH_LONG)
                .show();
    }
}

Android - disable landscape mode - Disable screen Orientation
the following code shows how to disable the screen orientation in android

Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml. For example:
        <activity android:name=".MainActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">