Showing posts with label Android ToggleButton on/off image. Show all posts
Showing posts with label Android ToggleButton on/off image. Show all posts

Monday, October 3, 2011

TextView font size color layout interface andoid exam

I created a new Android Project in Eclipse called “AndroidFonts”:

From here I modified the “main.xml” file in the layout folder.
<?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"
    >
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="MonoSpace Font:"
        android:textSize="16sp"
        android:paddingLeft="5sp"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5sp"
        android:typeface="monospace"
        android:text="Hello Red Monospace"
        android:textSize="16sp"
        android:textColor="#ff0000"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Sans Font:"
        android:textSize="16sp"
        android:paddingLeft="5sp"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5sp"
        android:typeface="sans"
        android:text="Hello Blue Sans"
        android:textSize="16sp"
        android:textColor="#0000ff"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Serif Font:"
        android:textSize="16sp"
        android:paddingLeft="5sp"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5sp"
        android:paddingRight="2sp"
        android:typeface="serif"
        android:text="Hello Green Serif"
        android:textSize="16sp"
        android:textColor="#00ff00"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5sp"
        android:paddingTop="15sp"
        android:typeface="normal"
        android:text="I'm normal font but I'm also bold and italic"
        android:textSize="16sp"
        android:textStyle="bold|italic"
        android:textColor="#ffffff"
        />
    <TextView
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5sp"
        android:paddingTop="15sp"
        android:paddingBottom="15sp"
        android:typeface="normal"
        android:text="I'm normal (bold) font but I have a shadow"
        android:textSize="16sp"
        android:textStyle="bold"
        android:shadowColor ="#0f0f0f"
        android:shadowRadius="1.6"
        android:shadowDx="1.5"
        android:shadowDy="1.3"
        android:textColor="#000000"
        android:background="#ffffff"
        />
</LinearLayout>
When I run the project I get this result in the emulator:

As you can see from the code I used the fonts: sans, serif, and monospace. Then I showed off how to make a string bold and italic:
android:textStyle="bold|italic"
Then a string utilizing the shadowing effect:
android:shadowColor ="#0f0f0f"
android:shadowRadius="1.6"
android:shadowDx="1.5"
android:shadowDy="1.3"
Colors are as simple as adding:
android:textColor="#ff0000"
Pretty easy!

Wednesday, September 28, 2011

Android ToggleButton on/off image

android:disabledAlpha

Since: API Level
The alpha to apply to the indicator when disabled.
Must be a floating point value, such as "1.2".
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol disabledAlpha.
Related Methods

android:textOff

Since: API Level
The text for the button when it is not checked.
Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol textOff.
Related Methods

android:textOn

Since: API Level
The text for the button when it is checked.
Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol textOn.
//
main.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/LinearLayout01"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:gravity="center">

 <ToggleButton android:id="@+id/toggleButton01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textOff="Off Stage"
  android:textOn="On Stage"
  android:background="@drawable/icon"/>
 
</LinearLayout>

package com.dearpeople.android.test.togglebutton;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ToggleButton;
public class ToggleButtonActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        final ToggleButton tb = (ToggleButton)this.findViewById(R.id.toggleButton01);
       
        tb.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (tb.isChecked()) {
                 tb.setBackgroundDrawable(getResources().getDrawable(R.drawable.duke01));
                } else {
                 tb.setBackgroundDrawable(getResources().getDrawable(R.drawable.duke05));
                }
             }
        });
    }
}