Reputation: 797
I'm facing a problem where i have an app with no actionbar. I used a custom toolbar and I use this code for setup the toolbar
private void setupToolbar(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("Shopping Cart");
}
}
but the result shows an action bar with old items from mainActivity plus the toolbar added items.
Edited:
This is what looks like:
so you see two titles shown here I want to remove the icons(except back icon) and the home title that was created in main activity
Upvotes: 0
Views: 198
Reputation:
First you change style and select NoActionBar :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
and set CustomActionbar android :like this
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:id="@+id/toolbar_core"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="@+id/img_left_arrow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/_10sdp"
android:background="@android:color/transparent"
android:src="@drawable/ic_header_back"
android:visibility="visible" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/id_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:singleLine="true"
android:text="Catagory"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="@dimen/_18sdp" />
</LinearLayout>
<ImageView
android:id="@+id/Moreappps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/_10sdp"
android:background="@android:color/transparent"
android:src="@mipmap/ic_more_apps" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
I hope its help you
Upvotes: 1