2

It's hard to explain -- but all the toolbars I've tried adding in my project seem to be stuck in the corner.

I made a test layout to show it clearly:Test blueprint toolbar

Test blueprint toolbar

Click on image for a larger version of the image.

This is the xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="1000dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>

I've tried using different layouts. Also unable to drag the toolbar to resize it.

This is my real layout Real layout

And the code

<android.support.constraint.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:id="@+id/auth_request_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AuthRequestActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/activity_auth_request_toolbar"
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:layout_alignParentTop="true"
    android:background="@color/somecompanycolor"
    android:minHeight="@dimen/toolbar_height"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<fragment
    android:id="@+id/activity_auth_request_fragment"
    android:name="someexternalsdk"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_alignParentBottom="true"
    android:layout_below="@id/activity_auth_request_toolbar" />

</android.support.constraint.ConstraintLayout>

My code to set the toolbar:

mToolbar = findViewById(R.id.activity_auth_request_toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setTitle("Request");

For more info, I'm targeting 28.0.0-rc02, max sdk version 28, min 15.

Does anyone know what I'm doing wrong?

Shashanth
  • 4,995
  • 7
  • 41
  • 51
Cyn
  • 43
  • 4

2 Answers2

3

Edit 1

This seems to be bug on Android 28.0.0-rc02

Downgrade on 27 and dependence on 27.1.1 in your build.gradle will solve this issue

Original Answer

You are using a ConstraintLayout but your views are not constrained

this is the warning generally android studio show us when we not have any constraint defined

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime

define constraint for toolbar like this

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    tools:context=".Main2Activity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
Ashwini Saini
  • 1,324
  • 11
  • 20
  • Unfortunately that's not it. there's no warning generated by the ide and you'll notice that there are already constraints (totop/tobottomof) – Cyn Sep 23 '18 at 08:36
  • okay so what i found is if i use target sdk 27.1.1 then it's work perfectly but after tragting 28 this thing giving error..i'm trying to find a real solution for 28...but if you just want to run it then you can downgrade to 27.1.1..i'll update my answer when i'll find it. @Cyn – Ashwini Saini Sep 23 '18 at 09:11
  • 1
    Yes you are absolutely correct! Downgrading to 27.0.0 solved the problem. Thank you! Will mark this as accepted – Cyn Sep 23 '18 at 13:02
0

I have had similar issues, mostly when using constrained layout. Typical errors were

  1. Render Problem
  2. This view is not constrained. It only has design time positions, so it will jump to (0,0) at runtime unless you add the constraints
  3. Failed to load AppCompat ActionBar with unknown error

very closely resonate with your problems you describe in your post. Check images below and revert back if you encountering similar issues.

Missing Constraints

Similarly Look for Render Problems too.

Render Problems

Solution:

I would try what @Ashwini Violet has suggested.

In addition I suggest you checking your styles.xml file. If you have something like the following

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

I would recommending changing to

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

The key word here is Base

Try these and revert back if you need anymore help. H

Here are some other references that have help me in the past.

References:

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
  • 1
    Thanks for the suggestion. What @Ashwini Violet had suggested was correct. Downgrading to 27.0.0 is what solved it. – Cyn Sep 23 '18 at 13:03