Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set custom title bar TextView Value dynamically in android?

friends,

i have created custom title bar using following titlebar.xml file with code

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@+id/myTitle" 
  android:text="This is my new title" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:textColor="@color/titletextcolor"
  android:layout_marginLeft="25px"
   android:paddingTop="3px" 
   /> 

and java code to display custom title bar on each activity.

@Override
    public void onCreate(Bundle savedInstanceState)
    {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);

super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


}

now i want to set textview value dynamically in each activity can any one guide me how can i achieve this?

using findviewbyid here i dont get reference of that textview to set value because main layout does not contains any textbox with such a name but mytitle.

any help would be appriciated.

like image 410
UMAR-MOBITSOLUTIONS Avatar asked Mar 10 '10 12:03

UMAR-MOBITSOLUTIONS


1 Answers

This is the way to set the custom title:

@Override
protected 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.mytitle);
    }

    final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
    if ( myTitleText != null ) {
        myTitleText.setText("========= NEW TITLE ==========");
        myTitleText.setBackgroundColor(Color.GREEN);
    }


}
like image 134
Diego Torres Milano Avatar answered Nov 01 '22 21:11

Diego Torres Milano