Reputation: 4219
I am using different layouts to show different styled titles in my application. The problem is that I can't get a reference to a specific Textview that exists in all of them. If I change the text, nothing happens.
Here is what I am doing:
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
The following method does not work:
public void setTitle(String text) {
TextView txtTitle = (TextView) this.findViewById(R.id.txtTitle);
if(txtTitle !=null) {
txtTitleMoney.setText(text);
Log.d("debug", "not null");
}
}
I get no error so I think I'm accessing the wrong view.
Hopefully someone can help me :)
Upvotes: 2
Views: 293
Reputation: 1492
if you set the same id ("txtTitle
") to the TextView
items in all of your different title layouts, then your code should work.
also make sure you call setTitle()
after setContentView()
.
Upvotes: 5
Reputation: 22493
try this
boolean customTitleSupported;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.mainscreen);
customTitleBar();
}
public void customTitleBar( ) {
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.customtitlebar);
TextView title = (TextView) findViewById R.id.title);
title.setText(left);
}
}
Upvotes: 5