├── demo ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── font │ │ │ └── dosis.otf │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── drawable │ │ │ ├── ic_autorenew_black_24dp.xml │ │ │ └── ic_autorenew_white_24dp.xml │ │ ├── values-v27 │ │ │ └── styles.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── io │ │ └── github │ │ └── muddz │ │ └── styleabletoast │ │ └── demo │ │ └── MainActivity.java ├── proguard-rules.pro └── build.gradle ├── styleabletoast ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ ├── values │ │ │ ├── integers.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── attrs.xml │ │ ├── values-v27 │ │ │ ├── colors.xml │ │ │ └── dimens.xml │ │ ├── drawable-v27 │ │ │ └── shape_toast.xml │ │ ├── drawable │ │ │ └── shape_toast.xml │ │ ├── layout-v27 │ │ │ └── styleable_layout.xml │ │ └── layout │ │ │ └── styleable_layout.xml │ │ └── java │ │ └── io │ │ └── github │ │ └── muddz │ │ └── styleabletoast │ │ ├── Utils.java │ │ └── StyleableToast.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── cases.png ├── StyleableToastDemo.apk ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── readme.md ├── gradlew.bat ├── gradlew └── license /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /styleabletoast/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':demo', ':styleabletoast' 2 | -------------------------------------------------------------------------------- /cases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muddz/StyleableToast/HEAD/cases.png -------------------------------------------------------------------------------- /StyleableToastDemo.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muddz/StyleableToast/HEAD/StyleableToastDemo.apk -------------------------------------------------------------------------------- /styleabletoast/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/src/main/res/font/dosis.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muddz/StyleableToast/HEAD/demo/src/main/res/font/dosis.otf -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muddz/StyleableToast/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | StyleableToast demo 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 255 4 | 230 5 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values-v27/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #EEEEEE 5 | #de000000 6 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #555555 5 | #ffffff 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | -------------------------------------------------------------------------------- /demo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/drawable-v27/shape_toast.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/drawable/shape_toast.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /styleabletoast/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'com.vanniktech.maven.publish' 4 | } 5 | 6 | android { 7 | compileSdk 30 8 | 9 | defaultConfig { 10 | minSdk 16 11 | targetSdk 30 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation 'androidx.appcompat:appcompat:1.3.1' 23 | } 24 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values-v27/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14sp 5 | 22dp 6 | 7 | 8 | 21dp 9 | 23dp 10 | 11 | 24dp 12 | 15dp 13 | 14 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_autorenew_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_autorenew_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16sp 4 | 30dp 5 | 6 | 7 | 20dp 8 | 25dp 9 | 10 | 25dp 11 | 11.2dp 12 | 13 | 8dp 14 | 19dp 15 | 16 | 17 | -------------------------------------------------------------------------------- /styleabletoast/src/main/java/io/github/muddz/styleabletoast/Utils.java: -------------------------------------------------------------------------------- 1 | package io.github.muddz.styleabletoast; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | 6 | import androidx.core.text.TextUtilsCompat; 7 | import androidx.core.view.ViewCompat; 8 | 9 | import java.util.Locale; 10 | 11 | class Utils { 12 | static int toDp(Context context, int value) { 13 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()); 14 | } 15 | 16 | static boolean isRTL() { 17 | return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /styleabletoast/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdk 30 7 | 8 | defaultConfig { 9 | applicationId "io.github.muddz.styleabletoast.demo" 10 | minSdk 16 11 | targetSdk 30 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | 16 | buildFeatures { 17 | dataBinding true 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation 'androidx.appcompat:appcompat:1.3.1' 30 | implementation 'com.google.android.material:material:1.4.0' 31 | implementation 'io.github.muddz:styleabletoast:2.4.0' 32 | // implementation project(':styleabletoast') 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | android.useAndroidX=true 2 | android.enableJetifier=true 3 | 4 | #MavenCentral publish informations 5 | #Publish plugin: https://github.com/vanniktech/gradle-maven-publish-plugin 6 | GROUP=io.github.muddz 7 | POM_ARTIFACT_ID=styleabletoast 8 | VERSION_NAME=2.4.0 9 | 10 | POM_NAME=styleabletoast 11 | POM_DESCRIPTION=An Android library that takes the standard toast to the next level with many styling options. Works on all Android versions. 12 | POM_INCEPTION_YEAR=2021 13 | POM_URL=https://github.com/Muddz/StyleableToast 14 | 15 | POM_LICENSE_NAME=The Apache Software License, Version 2.0 16 | POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt 17 | POM_LICENSE_DIST=repo 18 | 19 | POM_SCM_URL=https://github.com/Muddz/StyleableToast 20 | POM_SCM_CONNECTION=scm:git:git://github.com/Muddz/StyleableToast.git 21 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/Muddz/StyleableToast.git 22 | 23 | POM_DEVELOPER_ID=Muddz 24 | POM_DEVELOPER_NAME=Muddi Walid 25 | POM_DEVELOPER_URL=https://github.com/Muddz -------------------------------------------------------------------------------- /styleabletoast/src/main/res/layout-v27/styleable_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 22 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/layout/styleable_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 23 | 24 | -------------------------------------------------------------------------------- /styleabletoast/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # StyleableToast 2 | [![](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16#l16) 3 | [![APK](https://img.shields.io/badge/Download-Demo-brightgreen.svg)](https://github.com/Muddz/StyleableToast/raw/master/StyleableToastDemo.apk) 4 | 5 | An Android library that takes the standard toast to the next level with many styling options. Style your toasts either by code or with a style in `styles.xml`. 6 | ## Cases 7 | 8 | 9 | 10 | 11 | ## Example with a style 12 | 13 | 1) Define a style in `styles.xml`. All available attributes: 14 | ```xml 15 | 30 | 31 | ``` 32 | 33 | 2) Pass your style in the static constructor and call `show();` 34 | 35 | ```java 36 | StyleableToast.makeText(context, "Hello World!", Toast.LENGTH_LONG, R.style.mytoast).show(); 37 | ``` 38 | 39 | ## Example with builder pattern 40 | ```java 41 | new StyleableToast 42 | .Builder(context) 43 | .text("Hello world!") 44 | .textColor(Color.WHITE) 45 | .backgroundColor(Color.BLUE) 46 | .show(); 47 | ``` 48 | 49 | 50 | ## Installation 51 | 52 | Add the dependency in your `build.gradle` 53 | ```groovy 54 | dependencies { 55 | implementation 'io.github.muddz:styleabletoast:2.4.0' 56 | } 57 | ``` 58 | 59 | ## License 60 | 61 | Copyright 2016 Muddi Walid 62 | 63 | Licensed under the Apache License, Version 2.0 (the "License"); 64 | you may not use this file except in compliance with the License. 65 | You may obtain a copy of the License at 66 | 67 | http://www.apache.org/licenses/LICENSE-2.0 68 | 69 | Unless required by applicable law or agreed to in writing, software 70 | distributed under the License is distributed on an "AS IS" BASIS, 71 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 72 | See the License for the specific language governing permissions and 73 | limitations under the License. 74 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /demo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 17 | 18 | 32 | 33 | 34 | 37 | 38 | 42 | 43 | 46 | 47 | 50 | 51 | 55 | 56 | 59 | 60 | 63 | 64 | 67 | 68 | 71 | 72 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /demo/src/main/res/values-v27/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 17 | 18 | 32 | 33 | 34 | 37 | 38 | 42 | 43 | 46 | 47 | 50 | 51 | 55 | 56 | 59 | 60 | 63 | 64 | 67 | 68 | 71 | 72 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 14 | 15 | 23 | 24 | 28 | 29 | 37 | 38 |