Friday, September 21, 2012
Android Set Font in xml and Java

In SDK Android provides three Droid fonts. Which are Droid sans , Droid Sans Mono and Droid Serif . We can set these system fonts to your android control either in XML or in Java Code.
1. Setting Font in XML layout.
Use android:typeface property in your control to set the system fonts. see the code below.
-------------------------------------------------------------------------------------
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="18dp"
android:typeface="serif"
/ >
-------------------------------------------------------------------------------------
In the above example.. i am used a TextView control to set the font serif
2. Setting Font using Java code.
-------------------------------------------------------------------------------------
TextView textView = (TextView) findViewById(R.id.TextView1);
textView.setTypeface(Typeface.SERIF);
-------------------------------------------------------------------------------------
In the above code setTypeface() method is used to set the TextView font to serif.
2:43 AM by sabeersas · 0
Sunday, September 16, 2012
Android EditText Hint ( Default Text )

In Android if we set the default text using EditText.setText(""); function , then we should write some more code for best function.
So the solution is you can simply set the hint in the XML file. just check the code below.
<EditText
android:id="@+id/editTextTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/defTitle">
</EditText>
In the above code hint property sets the text.
android:hint="@string/defTitle"
5:38 AM by sabeersas · 0
Subscribe to:
Posts (Atom)