首先刪除默認的動作條
編輯您的style.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme colors here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<!-- Disables the Default ActionBar -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然後在你的main_activity_layout.xml,刪除根的RelativeLayout標籤的填充。
下一頁
<android.support.v7.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/main_settings_btn"
android:background="@drawable/ic_settings"
android:backgroundTint="@color/accent"
android:contentDescription="Copy"/>
<ImageButton
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:background="@drawable/ic_points"
android:backgroundTint="@color/accent"
android:contentDescription="Paste"/>
</android.support.v7.widget.Toolbar>
...... <your_code_here_possibly_recyclerview>
這解決了你的額外工具欄上的問題。
下一頁
private Toolbar toolbar; // Declaring the Toolbar Object
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.mainToolbar); // Attaching the layout to the toolbar object
setSupportActionBar(toolbar); // Setting toolbar as the ActionBar with setSupportActionBar() call
// Now whenever you want to update the title just change text in below
getSupportActionBar().setTitle("My title");
}
這裏究竟是什麼你有問題?請清楚。 –
我也分享了截圖,額外的動作欄添加是問題,在代碼中我認爲問題在onCreateActionMode(); – sri
而不是膨脹一個菜單我假設你應該直接操縱工具欄的標題。 –