0

Trying to display a progress bar inside my activity's title bar, and I'm struggling how to make it neatly centered.

My code so far:

Progressbar layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="fill_horizontal" >

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:progress="50" />
</RelativeLayout>

Activity layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


    </android.support.v7.widget.Toolbar>
</LinearLayout>

Java code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view);

    Toolbar myToolbar = (Toolbar) findViewById(R.id.activity_toolbar);
    setSupportActionBar(myToolbar);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
    View progress = getLayoutInflater().inflate(R.layout.progressbar_layout, null);
    getSupportActionBar().setCustomView(progress);
}

pretty straightforward, but results are quite horrible, the whole thing just looks weird...

Screenshot of uncentered progressbar

Same thing in layout inspector

Screenshot of layout inspector with uncentered progressbar

Any idea how to proceed?

I don't need any other actionbar features besides menu and back arrow. Would it be possible to display these controls separately with expected behaviour? (which is quite complex, especially for overflow menu)

Or is it possible to alter ActionBar style so both sides have same size (AND padding/margin)?

Ideas?

miko3k
  • 57
  • 5

1 Answers1

0

okey .. check my answer on this question .. i think it might be helpful for you Title bar

  • 1
    Maybe I am overlooking something, but I do not see how it helps... My problem is that controls on both sides (back arrow and menu) have vastly different widths, so It is very hard to center anything in between. – miko3k Aug 30 '17 at 23:38
  • 1
    okey .. i tried a lot of solutions and what i got is that this space is created by android back arrow default so you have two solution for it. First one by setting a marginStart for you `RelativeView` in **ProgressLayout.xml** to look like in the middle. the second is that (what i prefered) you set your owner bar Toolbar as i mentioned in the link and i can help you to do it if you want. – Mohamed Nagy Mostafa Aug 31 '17 at 01:09