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?