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 に答える