0

我想在整个应用程序中重用标题栏布局,但我想更改每个Activity.

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

是否可以在 XML 中执行此操作,或者我是否需要在每个代码中执行此操作Activity

4

1 回答 1

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);
       }
   }
}
于 2012-04-26T13:51:36.817 回答