-1

enter image description here

Please Look at below Picture,

And here is code :

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {

        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);

        View view = getLayoutInflater().inflate(R.layout.action_bar, null);

        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(view, layoutParams);
        view.getLayoutParams().width = ActionBar.LayoutParams.MATCH_PARENT;
        Toolbar parent = (Toolbar) view.getParent();
        parent.setContentInsetsAbsolute(0, 0);


        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
            View bottom = findViewById(R.id.bottomLayout_FrameLayout_LoginActivity);
            bottom.getLayoutParams().height = actionBarHeight;

        }
        tvTitleActionBar = (TextView) actionBar.getCustomView().findViewById(R.id.title_TextView_ActionBar);

        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    }

R.layout.action_bar:

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/head_bottom_blue_color">

    <ImageView
        android:id="@+id/openSlideMenu_ImageView_ActionBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:clickable="true"
        android:src="@android:drawable/ic_menu_sort_by_size"
        android:visibility="gone" />

    <TextView
        android:id="@+id/title_TextView_ActionBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textAppearance="@android:style/TextAppearance.Medium"
        android:textColor="@android:color/white"
        android:textStyle="bold" />
</RelativeLayout>
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134

2 Answers2

0

This looks like the same problem addressed here - see the suggested answers- especially the selected answer OR the answer proposed by Amrut Bidri (in his case you add a few lines). Hopefully this solves your problem.

Community
  • 1
  • 1
ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32
0

Add these to styles

<style name="MyActionBar" parent="@style/Base.Widget.AppCompat.ActionBar">
    <item name="contentInsetStart">0dp</item>
    <item name="contentInsetEnd">0dp</item>
</style>

and then use it in your AppTheme like this

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>

Hope it helps

Atiq
  • 14,435
  • 6
  • 54
  • 69