如何在Android中的自定义标题栏中显示不同的按钮

时间:2011-08-11 03:37:12

标签: android customization titlebar

我看过很多关于如何根据打开的活动动态更改自定义标题栏文本的指南,但我不知道如何为不同的活动添加或放入不同的按钮。

例如,在一个页面中,我想添加一个“+”按钮来添加更多朋友,但我不希望其他活动。感谢

1 个答案:

答案 0 :(得分:0)

更好的方法是为要更改的每个活动创建自定义标题栏,此代码更改标题栏添加到super.onCreate(savedInstanceState)下面;

 final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.checkin);
    if (customTitleSupported) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                R.layout.title);
    }
  final TextView myTitleText = (TextView) findViewById(R.id.title);
    if (myTitleText != null) {
        myTitleText.setText(R.string.title_check_in);
    }

其中R.layout.checkin是活动布局,R.layout.title是标题布局 谢谢。

相关问题