0

我创建了一个自定义标题栏,它包含一个 TextView 和标签。我已将其添加到以下活动中

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.homepage);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.windowtitle);

但现在我想在标题栏中的文本视图中显示当前时间。

如何才能做到这一点?

4

2 回答 2

1

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  ");     
  }
}
于 2012-10-10T08:50:05.307 回答
1

请尝试以下代码

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());
于 2012-10-10T08:47:44.980 回答