Back button without action bar

Asked

Viewed 771 times

0

I removed the action bar from a single acitivity. But in my Action bar has the back button. If I remove the action bar logically the button comes out together. But I would like the button come back, stayed there. Is there a Toolbar or something where the back button is transparent and remains ?. I’m drawing a detail screen of a client’s record. Follow the images for better understanding.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Toolbar está ficando na frente agora

XML code:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary" />

inserir a descrição da imagem aqui

  • Are you using Toolbar or even Actionbar? If you are using Toolbar you can set its background as transparent. Already if you are using Actionbar even I advise you to change to Toolbar because it is much easier to customize it.

  • 1

    Eai @Bruno. I am using action bar. I will redo all my code then and in place of Action I will use the Toolbar. Thank you.

  • Study the immersive modes: https://developer.android.com/training/system-ui/immersive.html I think it will bring more usability to what you want to do.

  • @Matthew, I’ll take a look here. Thanks for your help.

  • @Bruno, I implanted Toolbar in my project. But when it comes to the Listview part, it surpasses Toolbar. Is there a command to fix Toolbar ?

  • By 'overtake' Voce means that Listview is behind Toolbar?

  • @Bruno, that’s right. I was able to solve it. I just took the Toolbar code and put it in after the Listview code. It worked. But it got really weird. No shading on Toolbar. And the list now exceeds Toolbar, but is not in front. I put the image in my question above.

  • I don’t understand exactly what you want. Do you want only the button? If so, make Toolbar transparent with android:Theme="@style/Apptheme.ActionBar.Transparent"

  • @Leonardoassunção I understood your argument. But I can make Toolbar transparent only on this screen ? I created a file called Toolbar and reuse it on another screen with the <include command. It will work ?

  • Putting this theme, only the Toolbar of this layout will be transparent

Show 5 more comments

2 answers

1


Try the following:
Wrap your Toolbar with the AppBarLayout

      <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            // ... Sua ToolBar vai aqui

      </android.support.design.widget.AppBarLayout>

And below the AppBarLayout you add your ListView with the property app:layout_behavior="@string/appbar_scrolling_view_behavior":

<ListView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    ...>

 </ListView>
  • Bruno, I tried to perform the procedure as you told me and it returns the following error: java.lang.Classcastexception: android.support.design.widget.Appbarlayout cannot be cast to android.support.v7.widget.Toolbar

  • Show me your xml, because this error is usually written error.

  • Just remember that your Toolbar xml call has to look like this: <android.support.v7.widget.Toolbar. And in its code java import also has to be: import android.support.v7.widget.Toolbar

  • Bruno, I put what you showed me there in my code Toolbar and still returns me the same error. There on top of my question, I edited and put the xml of Toolbar. Check there. Thanks.

  • And in your java code the import is as shown above? if you can show the line that the error is occurring.

  • The error Voce described, is saying that Voce cannot convert an Appbarlayout into a Toolbar, this usually happens when your import is calling an old version of Toolbar instead of the v7 support library.

  • Bruno, I also found this. I went there in my Java code and its import is correct as you soliciou. import android.support.v7.widget.Toolbar;

  • Show the entire xml.

  • I put it there in the chat. Could be ?

Show 5 more comments

0

Try this code

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"      
            android:theme="@style/AppTheme.ActionBar.Transparent"
            app:layout_scrollFlags="scroll|enterAlways"

And in Styles.xml add

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
    <item name="colorPrimary">@android:color/transparent</item>
    <item name="colorControlNormal">@color/white</item>
</style>
  • Leonardo, I did what you asked. In my Java I also imported the class as you asked. I took a print. I put it there in my question. Last print. Toolbar is still superimposed over my listview and changed color. But the color is the least.

  • android strip:background="? attr/colorPrimary" to take the color. It was my mistake and I already edited. Do you want the list view to be below Toolbar? That is, that it does not overlap the listview?

  • That’s right. Listview overlaps Toolbar. But I think there must be some problem in Toolbar, because when he used the action bar he was right.

  • try using a relative layout and put in the android listview:layout_below="@id/Toolbar"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.