Search code examples
androidandroid-actionbarandroid-recyclerviewandroid-toolbarhorizontalscrollview

Android - Display file path in Toolbar


I am searching for a way to display a file path in the toolbar like this:

It needs to be clickable and should be swipeable if it's a long path. (Or small device).

I thought about using a HorizontalScrollView with a TextView and ImageView, but don't know if that is the best way to accomplish this. Is there a better (simpler) way to do this? Thanks!

Edit:

With thanks to @aelimill I found out that a RecyclerView can go horizontally, but I'm still having some issues. If you click on the text in the previous screenshot it shows this:

But for me (after I set the custom list item to clickable) it is like this:

(Look at the click animation)

How can I display the circle animation just like other ActionBar items?


Solution

  • I solved this by using a RecyclerView as @aelimill suggested. This is the custom list item I used:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:id="@+id/relativeLayout">
    
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/imageButton"
            android:src="@drawable/ic_keyboard_arrow_right_white_24dp"
            android:background="@null"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignTop="@+id/textView"
            android:layout_alignBottom="@+id/textView" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textView"
            android:background="?android:attr/selectableItemBackgroundBorderless"
            android:clickable="true"
            android:focusable="true"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/imageButton"
            android:layout_toEndOf="@+id/imageButton"
            android:gravity="center"
            android:textSize="16sp"
            android:minWidth="20dp"
            android:textColor="#ffffff"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

    Use selectableItemBackground instead of selectableItemBackgroundBorderless to support pre lollipop devices. (It wont be a circle animation, but a rectangle animation).