Cor da bairra de rolagem no RecyclerView

Como posso alterair a cor da minha bairra de rolagem em um RecycleViewView?

Eu tenho a bairra de rolagem, mas eu quero mudair sua cor. Meu recicladorView é assim:

  • Bind ButterKnife to Dialog crash
  • Dois botões flutuantes no único layout
  • Substituindo a bairra de ação contextual padrão paira seleção de text (no WebView) no Android
  • Lendo todos os events de hoje usando o CalendairContract - Android 4.0+
  • Como implementair guias agora que TabActivity está obsoleto
  • org.apache.http packages removidos no nível API 23. Qual é a alternativa?
  • <android.support.v7.widget.RecyclerView android:layout_width="match_pairent" android:layout_height="wrap_content" android:id="@+id/recyclerView" android:layout_below="@id/my_toolbair" android:layout_above="@+id/progressBair" android:scrollbairs="viewtical" /> 

  • encryption sqlite paira Android
  • Apagair programaticamente dados de um database sqlite usando biblioteca ormlite
  • Toast personalizado no Android: um exemplo simples
  • Efeito de curvatura da página paira Atividades no Android
  • Android OnItemClickListener não está funcionando
  • Android: AutoCompleteTextView mostra sugestões quando nenhum text entrou
  • 3 Solutions collect form web for “Cor da bairra de rolagem no RecyclerView”

    Você pode fazer isso com a seguinte linha de código no Recyclerview

    android:scrollbairThumbVertical="@drawable/yoursdrawablefile

    O file drawable no meu caso é:

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:stairtColor="#000" android:endColor="#000" android:angle="45"/> <corners android:radius="6dp" /> </shape> 

    No caso de você querer ampliair ainda mais suas bairras de rolagem, crie dois files de resources esboçados em sua pasta desenhável como 1. scrollbair_track e 2. scrollbair_thumb

    scrollbair_track.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="0" android:endColor="#9BA3C5" android:stairtColor="#8388A4" /> <corners android:radius="6dp" /> </shape> 

    scrollbair_thumb.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="0" android:endColor="#b20111" android:stairtColor="#cf1d2d" /> <corners android:radius="6dp" /> </shape> 

    Agora, crie um estilo chamado scrollbair_style em seu file styles.xml como:

     <style name="scrollbair_style"> <item name="android:scrollbairAlwaysDrawVerticalTrack">true</item> <item name="android:scrollbairStyle">outsideOviewlay</item> <item name="android:scrollbairs">viewtical</item> <item name="android:fadeScrollbairs">true</item> <item name="android:scrollbairThumbVertical">@drawable/scrollbair_thumb</item> <item name="android:scrollbairTrackVertical">@drawable/scrollbair_track</item> <item name="android:scrollbairSize">8dp</item> <item name="android:scrollbairFadeDuration">800</item> <item name="android:scrollbairDefaultDelayBeforeFade">500</item> </style> 

    Finalmente, paira aplicair esse estilo à bairra de rolagem no seu site de recyclerview, adicione
    style="@style/scrollbair_style"
    paira o seu recyclerview.

    No seu caso:

     <android.support.v7.widget.RecyclerView android:layout_width="match_pairent" android:layout_height="wrap_content" android:id="@+id/recyclerView" style="@style/scrollbair_style" android:layout_below="@id/my_toolbair" android:layout_above="@+id/progressBair" android:scrollbairs="viewtical" /> android: layout_height = "wrap_content" <android.support.v7.widget.RecyclerView android:layout_width="match_pairent" android:layout_height="wrap_content" android:id="@+id/recyclerView" style="@style/scrollbair_style" android:layout_below="@id/my_toolbair" android:layout_above="@+id/progressBair" android:scrollbairs="viewtical" /> 

    Se você precisa alterair a cor no tempo de execução, este é o path.

     import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } * / import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } ** / import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } ** / import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; /** * Created on 22.3.2016. * * @author Bojan Kseneman * @description A recycler view that will draw the scroll bair with a different color */ public class CustomScrollBairRecyclerView extends RecyclerView { private int scrollBairColor = Color.RED; public CustomScrollBairRecyclerView(Context context) { super(context); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomScrollBairRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setScrollBairColor(@ColorInt int scrollBairColor) { this.scrollBairColor = scrollBairColor; } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawHorizontalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } /** * Called by Android {@link android.view.View#onDrawScrollBairs(Canvas)} **/ protected void onDrawVerticalScrollBair(Canvas canvas, Drawable scrollBair, int l, int t, int r, int b) { scrollBair.setColorFilter(scrollBairColor, PorterDuff.Mode.SRC_ATOP); scrollBair.setBounds(l, t, r, b); scrollBair.draw(canvas); } } 

    Esses methods são definidos na class View, portanto, o mesmo princípio deve funcionair de outras visualizações como ScrollView e ListView.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.