=>This Tutorial can be used for different font types ,font color,font size and also Text Background Color can be set.
=>This Tutorial can provide facility to select option to drop down box in different category in android eclipse editor.
fontEditor Layout
Fonteditor.xmlfile
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/r"
tools:context=".MainActivity" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:entries="@array/font1"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="32dp"
android:ems="10"
android:hint="Here Type Something" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner1"
android:entries="@array/FontSize"/>
<Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner2"
android:layout_below="@+id/spinner2"
android:layout_marginLeft="36dp"
android:layout_marginTop="30dp"
android:entries="@array/Effect" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner3"
android:layout_below="@+id/spinner3"
android:layout_marginTop="55dp" android:entries="@array/Color"/>
<Spinner
android:id="@+id/spinner5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner4"
android:layout_below="@+id/spinner4"
android:layout_marginLeft="25dp"
android:layout_marginTop="17dp"
android:entries="@array/Backgroundcolor"
/>
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/r"
tools:context=".MainActivity" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:entries="@array/font1"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="32dp"
android:ems="10"
android:hint="Here Type Something" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner1"
android:entries="@array/FontSize"/>
<Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner2"
android:layout_below="@+id/spinner2"
android:layout_marginLeft="36dp"
android:layout_marginTop="30dp"
android:entries="@array/Effect" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner3"
android:layout_below="@+id/spinner3"
android:layout_marginTop="55dp" android:entries="@array/Color"/>
<Spinner
android:id="@+id/spinner5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner4"
android:layout_below="@+id/spinner4"
android:layout_marginLeft="25dp"
android:layout_marginTop="17dp"
android:entries="@array/Backgroundcolor"
/>
</RelativeLayout>
fonteditor javafile
package com.example.fonteditor;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
Spinner sp1,sp2,sp3,sp4,sp5;
EditText e1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp1=(Spinner)findViewById(R.id.spinner1);
sp2=(Spinner)findViewById(R.id.spinner2);
sp3=(Spinner)findViewById(R.id.spinner3);
sp4=(Spinner)findViewById(R.id.spinner4);
sp5=(Spinner)findViewById(R.id.spinner5);
e1=(EditText)findViewById(R.id.editText1);
sp4.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//String c=arg0.getItemIdAtPosition(arg2);
String c=arg0.getItemAtPosition(arg2).toString();
if(c.equals("Red"))
{
e1.setTextColor(Color.RED);
}
if(c.equals("Green"))
{
e1.setTextColor(Color.GREEN);
}
if(c.equals("Blue"))
{
e1.setTextColor(Color.BLUE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp5.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//String c=arg0.getItemIdAtPosition(arg2);
String c=arg0.getItemAtPosition(arg2).toString();
if(c.equals("Red"))
{
e1.setBackgroundColor(Color.RED);
}
if(c.equals("Green"))
{
e1.setBackgroundColor(Color.GREEN);
}
if(c.equals("Blue"))
{
e1.setBackgroundColor(Color.BLUE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s3=arg0.getItemAtPosition(arg2).toString();
if(s3.equals("Bold"))
{
Typeface t=Typeface.create("", Typeface.BOLD);
e1.setTypeface(t);
}
if(s3.equals("Italic"))
{
Typeface t=Typeface.create("", Typeface.ITALIC);
e1.setTypeface(t);
Toast.makeText(getApplicationContext(), "hello", 20).show();
}
if(s3.equals("Bold|Italic"))
{
Typeface t=Typeface.create("", Typeface.BOLD_ITALIC);
e1.setTypeface(t);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp2.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s2=arg0.getItemAtPosition(arg2).toString();
float f=Float.parseFloat(s2);
e1.setTextSize(f);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s1=arg0.getItemAtPosition(arg2).toString();
if(s1.equals("Font-1"))
{
String path="fonts/BrotherTattoo_Demo.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
if(s1.equals("Font-2"))
{
String path="fonts/Admiration Pains.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
if(s1.equals("Font-3"))
{
String path="fonts/Jonquilles.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
Spinner sp1,sp2,sp3,sp4,sp5;
EditText e1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp1=(Spinner)findViewById(R.id.spinner1);
sp2=(Spinner)findViewById(R.id.spinner2);
sp3=(Spinner)findViewById(R.id.spinner3);
sp4=(Spinner)findViewById(R.id.spinner4);
sp5=(Spinner)findViewById(R.id.spinner5);
e1=(EditText)findViewById(R.id.editText1);
sp4.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//String c=arg0.getItemIdAtPosition(arg2);
String c=arg0.getItemAtPosition(arg2).toString();
if(c.equals("Red"))
{
e1.setTextColor(Color.RED);
}
if(c.equals("Green"))
{
e1.setTextColor(Color.GREEN);
}
if(c.equals("Blue"))
{
e1.setTextColor(Color.BLUE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp5.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//String c=arg0.getItemIdAtPosition(arg2);
String c=arg0.getItemAtPosition(arg2).toString();
if(c.equals("Red"))
{
e1.setBackgroundColor(Color.RED);
}
if(c.equals("Green"))
{
e1.setBackgroundColor(Color.GREEN);
}
if(c.equals("Blue"))
{
e1.setBackgroundColor(Color.BLUE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s3=arg0.getItemAtPosition(arg2).toString();
if(s3.equals("Bold"))
{
Typeface t=Typeface.create("", Typeface.BOLD);
e1.setTypeface(t);
}
if(s3.equals("Italic"))
{
Typeface t=Typeface.create("", Typeface.ITALIC);
e1.setTypeface(t);
Toast.makeText(getApplicationContext(), "hello", 20).show();
}
if(s3.equals("Bold|Italic"))
{
Typeface t=Typeface.create("", Typeface.BOLD_ITALIC);
e1.setTypeface(t);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp2.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s2=arg0.getItemAtPosition(arg2).toString();
float f=Float.parseFloat(s2);
e1.setTextSize(f);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sp1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s1=arg0.getItemAtPosition(arg2).toString();
if(s1.equals("Font-1"))
{
String path="fonts/BrotherTattoo_Demo.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
if(s1.equals("Font-2"))
{
String path="fonts/Admiration Pains.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
if(s1.equals("Font-3"))
{
String path="fonts/Jonquilles.ttf";
Typeface tf=Typeface.createFromAsset(getAssets(), path);
e1.setTypeface(tf);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
font editor output