RSS

Android Displaying text using a theme.Dialog

02 Jul

I added afew stuff to the Menu(Check out the menu first if you haven’t ), now when you click on “About” it show this dialog box. Its basically implemented using an xml file containing a Text View:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello there I'm Gilbert currently(7/2/2012) a student at JKUAT Taita Taveta campus first year and this are my chronicles"

        />

</LinearLayout>

and a Java class that will have its setContentView() to the xml above:


package com.learning.gilo;

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

public class AboutUs extends Activity{

	protected void onCreate(Bundle b){
		super.onCreate(b);
		setContentView(R.layout.aboutus);
	}
}

Now at the main class the method that shall detect which item is selected is:

public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch(item.getItemId()){
		case R.id.about:
			Intent i = new Intent("com.learning.gilo.ABOUTUS");
			startActivity(i);

			break;
		}

BUT, the magic code that will start this activity as a Dialog is in the Android manifest:


<activity
            android:name=".AboutUs"
            android:label="About me"
            android:theme="@android:style/Theme.Dialog"
             >
            <intent-filter>
                <action android:name="com.learning.gilo.ABOUTUS" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

Its this part:

android:theme="@android:style/Theme.Dialog"
Advertisements
 
 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: