• Stars
    star
    1,961
  • Rank 23,637 (Top 0.5 %)
  • Language
    Java
  • Created about 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Material Design RatingBar with better appearance

MaterialRatingBar

Icon

Material Design RatingBar with better appearance, compatible with Android 3.0+.

Why MaterialRatingBar?

  • Consistent appearance on Android 3.0+.
  • Extends framework RatingBar.
  • Get the 2dp star border background as in Material Icons and Google apps.
  • Correct custom tinting across platforms.
  • Able to render correctly when layout_width is set to match_parent, as in Google Play Store.
  • Able to scale correctly when layout_height is set to values other than 16dp, 36dp and 48dp.
  • Able to display ratings such as 4.3 correctly, which will be filled to 4.5 by framework's incorrect implementation.
  • Avoid framework's sunken half star visual glitch.
  • Used as a drop-in replacement for framework RatingBar.

Preview

Google Play

Sample APK

Sample app

Integration

Gradle:

implementation 'me.zhanghai.android.materialratingbar:library:1.4.0'

Usage

Simply replace your RatingBar with MaterialRatingBar, and remember to apply a corresponding style for correct behavior.

For example, to create a normal MaterialRatingBar:

<me.zhanghai.android.materialratingbar.MaterialRatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/Widget.MaterialRatingBar.RatingBar" />

In order to make your RatingBar take the correct and consistent size on all versions, you will always need to use one of the styles from this library. The trick inside it is android:minHeight and android:maxHeight that controls the drawable height.

You can checkout more small or indicator variants in styles.xml.

You can use app:mrb_fillBackgroundStars to control whether background stars are filled, otherwise it defaults to the same value as android:isIndicator which is the behavior of Google apps.

8 tint-related attributes such as app:mrb_progressTint and app:mrb_progressTintMode are also supported so that they can control the tinting of rating drawables. The default tint color is ?colorControlActivated, and the default tint mode is src_in.

An OnRatingChangeListener interface is also added to MaterialRatingBar, which enables callback while user is dragging, just as the listener in SeekBar.

For a detailed example, you can refer to the sample app's layout, where you can find examples such as tinting and wide layout.

Design

Filled star or star border

The framework's RatingBar uses filling stars with grey color as track, however as per the Material Icons site, star border icons are given.

Material Icons

And as for the Google Play Store and Google I/O app, they are both using the star borders as track.

Google Play Store Google I/O

With Google's design practice and aesthetic considerations taken into account, I decided to use the star border style.

Star size

Google Play Store has stars of optical size 24dp, while Google I/O app and framework Widget.Material.RatingBar.Indicator have stars of size 36dp (which are of optical size 30dp). (The framework's default size of 64dp is ridiculously large and thus not taken into consideration.)

Also noticing that the Material Icons site gives icons of 24dp (optical 20dp) and 36dp (optical 30dp), I decided to stick to the 36dp approach which is also visually pleasant.

Star border width

The ring for radio button in Material Design has a width of 2dp, and with experiments on other border widths, I decided to adopt the 2dp border width.

The star border icon is drawn with the help of Inkscape, by downloading the star icon SVG from Material Icons, duplicating the outer border path of the star, setting a stroke of 4dp, running stroke to path on it, extracting the inner border path, and finally combining this path and the original outer border path.

Wide layout

Framework RatingBar gives erroneous rendering for RatingBar when layout_width is set to match_parent by tiling the stars without any gap. Since Google Play Store employed the wide design, I implemented it inside this library as well, so that match_parent will work properly for MaterialRatingBar.

Dragging

Google Play Store and Google I/O app both used an implementation other than RatingBar, which means dragging on the bar across stars won't work (it is the functionality of AbsSeekBar). I think this is a handy way of interaction for users, and it enables the setting of 0 star which can be useful if you want to enable users to reset their rating to unrated.

License

Copyright 2016 Zhang Hai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

MaterialFiles

Material Design file manager for Android
Kotlin
5,968
star
2

Douya

开源的 Material Design 豆瓣客户端(A Material Design app for douban.com)
Java
4,548
star
3

MaterialProgressBar

Material Design ProgressBar with consistent appearance
Java
2,215
star
4

MaterialColdStart

Utilize the window background during cold start time to make your app look faster.
Shell
1,225
star
5

AndroidFastScroll

Fast scroll for Android RecyclerView and more
Java
701
star
6

PatternLock

Material Design Pattern Lock with auth flow implementation
Java
689
star
7

CustomTabsHelper

Custom tabs, made easy.
Java
386
star
8

Untracker

App to help you remove tracking information before sharing links
Kotlin
366
star
9

ComposePreference

Preference implementation for Jetpack Compose Material 3
Kotlin
182
star
10

archexp

浙江大学计算机体系结构课程实验
Verilog
166
star
11

AppIconLoader

Android app icon loader from AOSP iconloaderlib
Java
162
star
12

MaterialEditText

Material Design EditText with a delightful linear ripple in background
Java
146
star
13

zju-csse-undergraduate-design-latex-template

浙江大学计算机科学与技术、软件工程专业本科毕业设计 LaTeX 模板
TeX
138
star
14

SystemUiHelper

Helper for dealing with Android System UI visibility
Java
117
star
15

BeeShell

Java REPL on Android with BeanShell
Kotlin
107
star
16

EffortlessPermissions

An Android permission library extending Google's EasyPermissions with convenient additions.
Java
86
star
17

TextSelectionWebSearch

Add web search to text selection toolbar on Android
Java
84
star
18

gnome-shell-extension-transparent-top-bar

GNOME Shell extension that brings back the transparent top bar when free-floating in GNOME Shell 3.32
JavaScript
77
star
19

DouyaApiKey

豆芽 API Key 设置向导
Java
69
star
20

DoubanYearProgress

Year progress for Douban
JavaScript
63
star
21

AndroidUtil

Utilities to make the life of an Android developer easier
Java
59
star
22

libarchive-android

libarchive as an Android library
C
56
star
23

AndroidSVGScripts

Bash scripts to automate and extend the process of using SVG as Android image asset
Shell
56
star
24

AndroidRetroFile

Backport of java.nio.file API (JSR 203) for Android
Java
47
star
25

mipsasm

MIPS assembler and IDE
Java
46
star
26

MaterialPlayPauseDrawable

Material Design play/pause Drawable with animation
Java
37
star
27

libselinux-android

libselinux as an Android library
C
24
star
28

join-screenshots.zhanghai.me

Join screenshots with HTML5
HTML
23
star
29

opengl-c-solarsystem

Animated solar system model implemented with OpenGL and FreeGLUT in C
C
22
star
30

orgexp

Computer Organization Experiment, Shi Qingsong, Zhejiang University.
Verilog
21
star
31

pykeymacs

Emacs style keyboard macros implemented in Python
Python
20
star
32

vntools

Tools for working with visual novels
C++
18
star
33

filesystem-kt

Multiplatform Kotlin library for accessing files and file systems
Kotlin
17
star
34

deadbeef-gnome-mmkeys

Add GNOME multimedia keys support in DeadBeef player using DBus
C
16
star
35

collision-detection-bubbles

A collision detection and resolution experiment with Two.js
JavaScript
16
star
36

gtkmmproject

Gtkmm CLion Project
CMake
12
star
37

linenoise-android

Linenoise as an Android library
C
12
star
38

qt5project

Qt 5 CLion project
C++
10
star
39

Reflected

Java library for easy-to-use reflection
Java
9
star
40

AndroidLibraryTemplate

Android library template
9
star
41

SeekBarPreference

A Preference that shows a dialog with a SeekBar widget.
Java
9
star
42

Bytecoder

Android gradle plugin to generate bytecode for accessing any method or field
Java
9
star
43

Functional

Java library for JavaScript-like functional methods
Java
8
star
44

zhsh

A minimal interactive shell written in C.
C
8
star
45

DouyaCiBuilds

豆芽 CI 构建版本仓库
8
star
46

Palette

Sample application to showcase android.support.v7.graphics.Palette
Java
6
star
47

twitter-unwanted-follower-remover

Semi-automatic command line tool for removing unwanted followers on Twitter
JavaScript
5
star
48

particle-system-campfire

A particle system experiment with Two.js
HTML
5
star
49

AimBackend

Another Instant Messager app, backend.
JavaScript
5
star
50

AimAndroid

Another Instant Messager app, Android.
Java
5
star
51

kiscript

ECMAScript, kept simple.
C
5
star
52

ColorPicker

Android color picker from AOSP
Java
5
star
53

markdown-template

Zhang Hai's markdown template
JavaScript
4
star
54

gnome-shell-extension-es6-class-codemod

A jscodeshift transform that helps migrating GNOME Shell extensions to 3.32
JavaScript
4
star
55

Promise

Java library for JavaScript-like Promise
Java
4
star
56

ZJUWLANAutoLogin

A chrome extesion that enables auto login when redirected to login page on ZJUWLAN
JavaScript
4
star
57

resume.zhanghai.me

Zhang Hai's resume
HTML
4
star
58

gettext-po-parser

Gettext PO file parser
4
star
59

xkeymacs

X11 KEYboard MACroS
C
4
star
60

fpga-life-game

Conway's game of life implemented on FPGA with combinational logic
Verilog
3
star
61

zhclib

A C library written by me
C
3
star
62

translations.zhanghai.me

Search translations in open source projects
HTML
3
star
63

stone.zhanghai.me

(Zhang Hai's) The story of the stone
HTML
3
star
64

douya-website

Source of Zhang Hai's Douya project home
JavaScript
3
star
65

SsidTester

SSID tester for identifying ZJUWLAN difficulty. Also serves as a sample application for beginners.
Java
3
star
66

course_linux_programming

Linux programming course
C
3
star
67

zh-conf-backup

Backup script for Zhang Hai's configuration
Shell
3
star
68

Labyrinth

Labyrinth game with OpenGL
Java
3
star
69

resume-legacy

Source of Zhang Hai's resume, legacy version
CSS
2
star
70

slides.zhanghai.me

Zhang Hai's slides
HTML
2
star
71

douya.zhanghai.me

Zhang Hai's Douya
ApacheConf
2
star
72

api-functions-worth-calling

API - Functions worth calling
HTML
2
star
73

optical-system-mfc

Optical System with MFC
C
2
star
74

ExpressionEvaluator

Expression evaluator written in Java
Java
2
star
75

AimFrontend

Another Instant Messager app, frontend.
Vue
2
star
76

zh-minecraft-saves

My Minecraft saves.
Shell
2
star
77

FxPaint

Paint app written with JavaFx
Java
2
star
78

projects.zhanghai.me

Zhang Hai's projects
HTML
2
star
79

calc

C Topic Project - A calculator based on operator precedence
C
2
star
80

www.zhanghai.me

Zhang Hai's main site
HTML
2
star
81

aoe4-mod-superweapon-pvp

Add Siege Camp in campaign as a superweapon for the game (PvP version)
1
star
82

lms

C Topic Project - A simple Library Management System
C
1
star
83

SePolicyInject

Android library to inject rules into binary SELinux kernel policies
CMake
1
star
84

DataStructure

An object oriented implementation of fundamental data structures (and algorithms) using C++11
C++
1
star
85

WordList

A simple android application to display specially annotated English word lists
Java
1
star
86

optical-system-qt

Optical System with Qt
C
1
star
87

seafile-server-github-actions-build

Seafile Server built by GitHub Actions
1
star
88

reveal-md-template

Reveal.js template with reveal-md
Makefile
1
star
89

reveal-js-template

Zhang Hai's reveal.js template
Shell
1
star
90

ShowcaseView

A fork from legacy branch of https://github.com/amlcurran/ShowcaseView
Java
1
star
91

blog.zhanghai.me

Zhang Hai's blog
HTML
1
star
92

sevenzipjbind

Mirrored from git://sevenzipjbind.git.sourceforge.net/gitroot/sevenzipjbind/sevenzipjbind
C++
1
star
93

translations-index.zhanghai.me

Translations index
1
star
94

abnf-kt

ABNF parser generator for Kotlin
Kotlin
1
star