我想最好的方法是創建一個自定義操作欄並根據活動進行修改。這裏是一個例子..
首先,您必須創建自定義操作欄的佈局,以便根據您的要求定義功能。這裏是xml文件...
佈局自定義動作條:
<ImageView
android:id="@+id/custom_actionbar_back_iv"
android:layout_width="@dimen/small_margin_ar"
android:layout_height="@dimen/very_small_margin_ar"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/up_navigation"/>
<TextView
android:id="@+id/custom_actionbar_titleText_tv"
style="@style/wrapscreen"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/custom_actionbar_back_iv"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="@dimen/above_medium_text_size" />
<ImageButton
android:id="@+id/custom_actionbar_goToArchiveActivity_ib"
style="@style/wrapscreen"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/medium_margin"
android:background="@null"
android:src="@drawable/ic_action_overflow" />
這裏去執行..
定義setupactionBar()在onCreate方法()方法
private void setUpActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater layoutInflater = LayoutInflater.from(this);
View customActionBarView = layoutInflater.inflate(R.layout.custom_actionbar, null);
// this view is used to show tile
TextView ActivityTitleTV = (TextView) customActionBarView.findViewById(R.id.custom_actionbar_titleText_tv);
ActivityTitleTV.setText(R.string.title_text_archive);
//this view can be used for back navigation
ImageView backToRecorderIV = (ImageView) customActionBarView.findViewById(R.id.custom_actionbar_back_iv);
backToRecorderIV.setVisibility(View.VISIBLE);
backToRecorderIV.setOnClickListener(this);
//Another view which has up navigation
ImageButton goToArchiveActivityIB = (ImageButton) customActionBarView.findViewById(R.id.custom_actionbar_goToArchiveActivity_ib);
goToArchiveActivityIB.setVisibility(View.GONE);
actionBar.setCustomView(customActionBarView);
actionBar.setDisplayShowCustomEnabled(true);
}
//listener for back navigation
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.custom_actionbar_back_iv:
Intent recorder = new Intent(ArchiveActivity.this, RecorderActivity.class);
startActivity(recorder);
finish();
break;
}
}
希望這有助於...
來源
2015-05-11 11:44:16
SKG
那麼,如果你想標題改變基於標籤片段只是改變標題,如果我得到你的權利,否則使用'ViewPager'我認爲這會更好 – silverFoxA