I have the requirement that the appBar should look like this:
The background is simply transparent.
I use this layout to get an appBar (details hidden):
<android.support.v7.widget.Toolbar>
<TextView>
<ImageView>
</android.support.v7.widget.Toolbar>
Simply adding a view with height=1dp
below the ImageView
with layout_gravity="bottom
won't work.
Is it even possible to draw a line or a border in the ToolbarLayout
?
Android Apps/Applications Mobile Development This example demonstrates how to add a border to the top and bottom of an Android View. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/drawable/border_top_bottom.xml
Drag and drop a LinearLayout onto the screen and set the border background ( android:background="@drawable/customborder" ). In this example the existing single TextView is moved onto the LinearLayout.
This example demonstrates how do I draw a line in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Let's try to run your application.
How to add a border to the top and bottom of an Android View? This example demonstrates how to add a border to the top and bottom of an Android View . Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Using RelativeLayout like this:
<android.support.v7.widget.Toolbar>
<RelativeLayout>
<TextView>
<ImageView>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/button_menu"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Wrap the Toolbar in an AppBarLayout (which extends LinearLayout) and add the line as a view there:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
...>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
.../>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="..."
/>
</android.support.design.widget.AppBarLayout>
With AppBarLayout there will be a default "key line" on Android 21 and up and I had to turn it off in code with:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
findViewById (R.id.app_bar).setOutlineProvider (null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With