1

I want to add an indent from a icon, but I don't want to create the Toolbar. It should be. I solve the problem as follows, but this is not the right way:

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setTitle("   Maria");
    actionBar.setSubtitle("    last visited at 10:15 p.m.");
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setIcon(R.drawable.me);
}
Maria
  • 11
  • 1
  • 1
    Any reason why you don't want to use a (support) Toolbar? Main issue with Action bar is it's controlled by the system (not your app) so your control over it is very limited. – Pawel Sep 02 '19 at 14:27
  • I think creating the Toolbar just because of a space is impractical. – Maria Sep 02 '19 at 14:48
  • Eh, that's debatable. One of the main reasons to use your own `Toolbar` is to be able to customize it in ways that you can't through the `ActionBar` interface. Anyhoo, you should be able to [use a custom style for the `ActionBar`](https://stackoverflow.com/a/18288460), and setting the `android:contentInsetStartWithNavigation` value as you like. – Mike M. Sep 03 '19 at 11:58

1 Answers1

0

Please use custom app bar, you can customize your view as per need. Please refer below code:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">



    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar_main_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#343434"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

        >

        <RelativeLayout
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:id="@+id/rl_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent">



            <TextView
                android:id="@+id/tv_title"
                style="@style/text_wrap20"
                android:layout_width="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:ellipsize="end"
                android:gravity="center"
                android:paddingLeft="12dp"
                android:paddingRight="7dp"
                android:singleLine="true"
                android:text="Title"
                android:textColor="@color/white"
                />




        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>

</layout>
Hkh
  • 357
  • 1
  • 10