Reputation: 907
The ActionBar overlaps the TextView. Why? The constraints are correct imho. It works fine with RelativeLayout. I mainly use two ConstraintLayout to add some padding which should not affect the ActionBar.
Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffffff"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
android:layout_marginTop="10dp"
android:paddingRight="20dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/xxxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xxxxxxx"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#000000"
app:layout_constraintTop_toTopOf="@+id/constraintLayout2"
app:layout_constraintStart_toStartOf="@+id/constraintLayout2"/>
Upvotes: 0
Views: 699
Reputation: 1
Add this atribute to your main activity:
android:fitsSystemWindows="true"
Upvotes: 0
Reputation: 6981
change your 2nd ConstraintLayout height to wrap_content or if you want full height then give bottom constraint and height to 0dp like below
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffffff"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="@+id/xxxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xxxxxxx"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#000000"
app:layout_constraintStart_toStartOf="@+id/constraintLayout2"
app:layout_constraintTop_toTopOf="@+id/constraintLayout2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 2