Reputation: 1723
I have create a custom title bar, It contains a TextView and label. i have added this to an activity as follows
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.homepage);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.windowtitle);
But now i want to display current time in the textview inside the titlebar.
How can this be done?
Upvotes: 0
Views: 1645
Reputation: 22493
you can get text view like this.create a mytitle.xml
layout with textview
and then add this code it will work..
@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(" TITLE ");
}
}
Upvotes: 1
Reputation: 13785
Please try below code
LayoutInflater inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.windowtitle, null, true);
TextView textView = (TextView) view.findViewById(R.id.txtdate);
Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());
txtdate.setText(c.getTime());
Upvotes: 1