I'm trying to customize the title bar in my android application. In order to do that, I used accepted answer of this question.
Here is the code I used.
Here is my titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/ImageView01"
android:layout_width="57dp"
android:layout_height="wrap_content"
android:background="@drawable/ic_prof"/>
<TextView
android:id="@+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFA500"
/>
</LinearLayout>
Here is my main.xml
<?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"/>
Here is my TitleBar.java
package com.myayubo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
public class TitleBar extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if (myTitleText != null) {
myTitleText.setText("NEW TITLE");
// user can also set color using "Color" and then
// "Color value constant"
myTitleText.setBackgroundColor(Color.GREEN);
}
}
}
Here is my strings.xml
<string name="hello_world">Hello world!</string>
<string name="app_name">My Ayubo</string>
<color name="titlebackgroundcolor">#3232CD</color>
<color name="titletextcolor">#FFFF00</color>
But, I cannot customize my title bar using following code. I mean, code is running without any errors. But, it is not doing what I expected. What I need is to add an image and a title in to my header. How am I suppose to do that?