So I have a toolbar and it is the parent of a vertical linear layout containing two text views. When I run the activity without the up button everything looks fine. However, when I add the up button it appears to push the linear layout to the right. It seems like there's an implicit horizontal linear layout containing the up button and my own vertical linear layout.
If I cannot prevent the up button from doing this is there a way to set up the up button instead of doing it programmatically?
Sidenote: The reason I'm not using the ActionBar.SetTitle/SetSubtitle functions is because I can't style them how I want. However these functions don't have the same issue with the spacing.
Here's my activity code in my onCreate method. I've also added the relevant import statements:
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
//Get tool bar
Toolbar toolbar = (Toolbar) findViewById(R.id.thickToolBar);
setSupportActionBar(toolbar);
final ActionBar supportActionBar = getSupportActionBar();
supportActionBar.hide();
supportActionBar.setDisplayHomeAsUpEnabled(true); //If I comment out this line, things display normally. But ofc no up button
final TextView actionBarTitle = (TextView) findViewById(R.id.toolbar_title);
final TextView actionBarSubtitle = (TextView) findViewById(R.id.toolbar_subtitle);
supportActionBar.setDisplayShowTitleEnabled(false);
actionBarSubtitle.setText(query);
Here's my xml:
<?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:layout_margin="0dp"
android:orientation="vertical"
android:padding="0dp"
tools:context="com.kreyoldict.kreyoldict.DefinitionActivity">
<RelativeLayout
android:id="@+id/progressBarContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<ProgressBar
android:id="@+id/progressBarDefinitionActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible"/>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/thickToolBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="0dp"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:padding="0dp"
android:textAlignment="center"
android:theme="@style/AppActionBar"
android:visibility="visible"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_marginRight="0dp"
android:orientation="vertical"
android:padding="0dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Translated Word"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display2"
android:textColor="@android:color/white"/>
<TextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Original Text"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="@android:color/white"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ScrollView
android:id="@+id/scrollViewDefinitionActivity"
android:layout_width="match_parent"
android:layout_height="402dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewWordDefinition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/tv_detail_activity_word_definition"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Here's a picture of my
[component tree][1] never mind, I need more rep to post 3+ links.
Here's a pic of the app with the up button and layout bounds: up button shenanigans
It's kinda hard to see because my toolbar is red, but it seems like the linear layout begins where the up button ends.