包括稍有变化的布局

时间:2012-04-26 13:46:15

标签: android android-layout android-xml

我想在整个应用中重复使用标题栏布局,但我想更改每个Activity的标题文字。

包含的布局仅显示布局相关参数的自动完成选项。

是否可以在XML中执行此操作,还是需要在每个Activity的代码中执行此操作?

1 个答案:

答案 0 :(得分:0)

这样您就可以为每个活动的标题栏动态设置标题。

编辑:用于自定义标题栏。

public class TitleBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       final boolean iscustomTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

       setContentView(R.layout.main);


       if ( iscustomTitleSupported ) {
           getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);//the xml for custom titlebar is called here
           }

       final TextView TitleText = (TextView) findViewById(R.id.myTitle);
       if ( TitleText != null ) {
           TitleText.setText("NEW TITLE");

           // user can also set color using "Color" and then "Color value constant"
          // TitleText.setBackgroundColor(Color.GREEN);
       }
   }
}