-3

I am new to android and java, i need solution for a problem that I want a gif in the toolbar in android which is always running when the screen shows up, I am able to add gif using koral's library but I could not figure it out that how can I add this gif in toolbar I did this in iOS and able to add gif in tab bar, and I need same gif in android too, this is what I really want, any help would be appriciated

enter image description here

Arya
  • 1,729
  • 3
  • 17
  • 35
Ahsan
  • 173
  • 1
  • 13

3 Answers3

0

Create custom Toolbar layout like this. And put your gif, title etc here.

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <pl.droidsonroids.gif.GifImageView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:src="@drawable/src_anim"
           android:background="@drawable/bg_anim"/>

        //Other views

    </RelativeLayout>

</android.support.v7.widget.Toolbar>
Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52
0

Use notactiontoolbar and add custom toolbar in your layout this way you can add any child in toolbar tag for example use an imageview and kroals lib or glid to set gif in that imageview Following source will help you to undestand

 <android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="16dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="Home"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
            android:textColor="#fff" />

    </RelativeLayout>


</android.support.v7.widget.Toolbar>
Adeel Turk
  • 897
  • 8
  • 23
0

You can show gif images through Glide, which is image loading and caching library for Android.

XML Code:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/green"
        app:titleTextColor="@color/white" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/ivtest"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"/>
        </FrameLayout>

    </android.support.v7.widget.Toolbar>

Java Code:

    Glide.with(this).load(R.drawable.test_gif).asGif().into(imageViewGIF);

Preview:

enter image description here

Zeero0
  • 2,602
  • 1
  • 21
  • 36