Hi all….
Today in this post I will show you how to give a custom layout for the titleBar in ANDROID.
You can place almost anything inside a title using your custom layout.
Now go on and create a fresh project and copy this code into the main java file
package pack.coderzheaven; import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.widget.ProgressBar; import android.widget.TextView; public class CustomTitleDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); if (customTitleSupported) { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); TextView tv = (TextView) findViewById(R.id.tv); tv.setText( "CoderzHeaven" ); ProgressBar titleProgressBar = (ProgressBar) findViewById(R.id.PB); //titleProgressBar.setVisibility(ProgressBar.GONE); } } } |
Now create a new xml file and name it custom_title.xml and copy the following code to it.
<? xml version = "1.0" encoding = "utf-8" ?> < RelativeLayout android:id = "@+id/RelativeLayout01" android:layout_width = "fill_parent" android:layout_height = "fill_parent" xmlns:android = "http://schemas.android.com/apk/res/android" >. < ImageView android:layout_width = "40dip" android:id = "@+id/ImageView01" android:background = "@drawable/android_2" android:layout_height = "40dip" > </ ImageView > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:id = "@+id/tv" android:text = "CoderzHeaven" android:layout_toRightOf = "@+id/ImageView01" android:textColor = "@drawable/red" android:textStyle = "bold" android:layout_marginLeft = "5dip" android:layout_marginRight = "5dip" > </ TextView > < ProgressBar android:id = "@+id/PB" style = "?android:attr/progressBarStyleSmall" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_centerVertical = "true" android:layout_toRightOf = "@+id/tv" android:paddingLeft = "3dip" > </ ProgressBar > </ RelativeLayout > |
Note: remember to have images mentioned here in the drawable folder.
Now the strings.xml file where the color is defined.
<? xml version = "1.0" encoding = "utf-8" ?> < resources > < string name = "hello" >Hello World, Custom Title Bar from CoderzHeaven</ string > < drawable name = "white" >#ffffff</ drawable > < drawable name = "black" >#000000</ drawable > < drawable name = "blue" >#2554C7</ drawable > < drawable name = "green" >#347C2C</ drawable > < drawable name = "orange" >#ff9900</ drawable > < drawable name = "pink" >#FF00FF</ drawable > < drawable name = "violet" >#a020f0</ drawable > < drawable name = "grey" >#778899</ drawable > < drawable name = "red" >#C11B17</ drawable > < drawable name = "yellow" >#FFFF8C</ drawable > < drawable name = "PowderBlue" >#b0e0e6</ drawable > < drawable name = "brown" >#2F1700</ drawable > < drawable name = "Hotpink" >#7D2252</ drawable > </ resources > |
Atlast the AndroidManifest.xml file.
<? xml version = "1.0" encoding = "utf-8" ?> < manifest xmlns:android = "http://schemas.android.com/apk/res/android" package = "pack.coderzheaven" android:versionCode = "1" android:versionName = "1.0" > < application android:icon = "@drawable/icon" android:label = "CustomTitleDemo" > < activity android:name = ".CustomTitleDemo" android:label = "CustomTitleDemo" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > </ application > </ manifest > |
Please leave your valuable comments if you found this post useful………
can u give me turorial of how to create colourpicker dialog in android
thanks
All irght Ishan.. wait for that you will get it soon . Tell about this site to your colleagues. Keep visiting our site……..
You’ve got great insights about One Click Fix, keep up the good work!
Pingback: android set custom title bar related to array adapter | Software development support, software risk,bugs for bugs, risk analysis,