GithubHelp home page GithubHelp logo

muddz / styleabletoast Goto Github PK

View Code? Open in Web Editor NEW
2.1K 57.0 270.0 12.76 MB

[Moved to MavenCentral] An Android library that takes the standard toast to the next level with many styling options. Works on all Android versions.

License: Apache License 2.0

Java 100.00%
android toast java android-library styleabletoast

styleabletoast's Introduction

StyleableToast

APK

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.

Cases

Example with a style

  1. Define a style in styles.xml. All available attributes:
    <style name="mytoast">
        <item name="stTextBold">true</item>
        <item name="stTextColor">#fff</item>
        <item name="stFont">@font/retrofont</item>
        <item name="stTextSize">14sp</item>
        <item name="stColorBackground">#fff</item>
        <item name="stSolidBackground">true</item>
        <item name="stStrokeWidth">3dp</item>
        <item name="stStrokeColor">#fff</item>
        <item name="stIconStart">@drawable/ic</item>
        <item name="stIconEnd">@drawable/ic</item>
        <item name="stLength">LONG</item> LONG or SHORT
        <item name="stGravity">top</item> top or center
        <item name="stRadius">5dp</item>
    </style>
  1. Pass your style in the static constructor and call show();
    StyleableToast.makeText(context, "Hello World!", Toast.LENGTH_LONG, R.style.mytoast).show();

Example with builder pattern

        new StyleableToast
                .Builder(context)
                .text("Hello world!")
                .textColor(Color.WHITE)
                .backgroundColor(Color.BLUE)
                .show();

Installation

Add the dependency in your build.gradle

dependencies {
    implementation 'io.github.muddz:styleabletoast:2.4.0'   
}

License

Copyright 2016 Muddi Walid

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.

styleabletoast's People

Contributors

alexwyattdev avatar muddz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

styleabletoast's Issues

no possible to set margin for toast

it seems that there is not possibility to set margin for toast . so right now I can not find any solution to move it up , down , left , right for a little

How can change direction

Hi
I try add icon to toast with some text . how can move icon to right for right to left language.

There is no vertical position

If gravity set, it shows toast only in center. And changes horizontal position as one set in code with .gravity() method. Android built-in toast can be placed anywhere

Android resource linking failed for 2.1.3+

When I add your library to my build.gradle I get a Java compiler error during build for release 2.1.3 and upwards.

Android resource linking failed
..\android-app\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
..\android-app\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
..\android-app\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2922: error: resource android:attr/fontVariationSettings not found.
..\android-app\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2922: error: resource android:attr/ttcIndex not found.
error: failed linking references.

I use Android Studio 3.3, Gradle 3.3 and compile with the following configuration:
compileSdkVersion 26
minSdkVersion 23
targetSdkVersion 26

Does this Library Support WebP Image Drawable?

I am planning to use this awesome and useful library in my Android App. But does it support WebP format images? Also what would be the best suitable size of the drawable as the normal png image is not so clear while appearing in the Toast.

Show time duration

I would like to set show time duration to the toast, but I can't find anything related.

Icon Layering Issue

Hello,
I am having a issue where the icon is appearing behind the toast on some instances.
The code for each is the same besides the icon and the text.
Any Idea what the issue is?

Toast For Home Nav Clicked(Top)
StyleableToast st = new StyleableToast .Builder(MainActivity.this) .text("Home Nav Clicked") .textColor(Color.WHITE) .backgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorAccent)) .icon(R.drawable.ic_tab_home) .build(); st.show();

Toast For Add New Post(Bottom)
StyleableToast st = new StyleableToast .Builder(MainActivity.this) .text(fabButtonResult()) .textColor(Color.WHITE) .backgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorAccent)) .icon(R.drawable.ic_fab_add_message) .build(); st.show();

layeringissue

Great to see the AndroidX migration

Not really an issue but I'd like to say that I'm glad you're still looking into updating this library seeing the recent AndroidX related changes. Would be great to see a new release soon!

attr/radius already defined

If possible, rename the radius into toastRadius or something in attr.xml, so the projects can be built, probably in the new Android libraries 28.0.0 maybe there is a conflict.

lineSpacingExtra and textSize for the text

Setting lineSpacingExtra and textSize in style does not work. Can include this?

<style name="ToastNormal"> <item name="android:textColor">@android:color/white</item> <item name="android:textSize">30sp</item> <item name="android:lineSpacingExtra">8dp</item> <item name="android:fontFamily">fonts/GOTHAM-BOOK.ttf</item> <item name="android:colorBackground">@color/colorAccent2</item> </style>

More Methods Required

It would be better if other properties of Toast also like setGravity(), cancel(), etc. can be added just to make your StyleableToast complete in all manner.

Please don't use AndroidX Alpha version in release

The 2.2.1 release contains a dependency on androidx.appcompat:appcompat:1.1.0-alpha01.
Having a library depend on an alpha version causes trouble for apps that want to use stable(older) versions instead.

How to use spinIcon(); method?

How could I execute spinIcon(); on StyleableToast show?
Suppose this code:

StyleableToast.makeText(MainActivity.this, "Downloading...", Toast.LENGTH_LONG, R.style.onStartLoadingToast).show();

Compatibility issue with android 8.1

Hi,

Thanks for your tool, i'm using it on project with android 8.0.

But i started to work on a project with android 8.1

Will StyleableToast be compatible with android 8.1 ?

Thank you.

Regards, Sam.

Update existing instance of Toast

Hi, I am wondering is there any way we can update the content of the existing toast instance.
Just like mStyleableToast.setText("BLAH BLAH BLAH"); i find a similar function setToastMsg() but that didn't work well for lazy loading

Toast Length Issue

Toast Length LONG is lasting only for 2 seconds. How to Increase Toast Length to maximum 5- 8 seconds.

makeIcon() crashes on android 4.x devices

StyleableToast Version 2.2.0
Android 4.x

I am trying to create a stylableToast with an icon, which is loaded from the drawable folder. It works fine on newer android versions, but it crashes for android 4.x devices with the following exception.

Fatal Exception: android.content.res.Resources$NotFoundException: File res/drawable/ic_timepicker_light.xml from drawable resource ID #0x7f08006b
at android.content.res.Resources.loadDrawable + 3443(Resources.java:3443)
at android.content.res.Resources.getDrawable + 1921(Resources.java:1921)
at android.support.v4.content.ContextCompat.getDrawable + 465(ContextCompat.java:465)
at com.muddzdev.styleabletoast.StyleableToast.makeIcon + 183(StyleableToast.java:183)
at com.muddzdev.styleabletoast.StyleableToast.inflateToastLayout + 107(StyleableToast.java:107)
at com.muddzdev.styleabletoast.StyleableToast.createAndShowToast + 116(StyleableToast.java:116)
at com.muddzdev.styleabletoast.StyleableToast.show + 125(StyleableToast.java:125)

Builder Pattern

Would be good to use a builder pattern for creating a styled toast from code. So instead of the README example of

StyleableToast st = new StyleableToast(this, "Updating profile", Toast.LENGTH_SHORT);
st.setBackgroundColor(Color.parseColor("#ff5a5f"));
st.setTextColor(Color.WHITE);
st.setIcon(R.drawable.ic_autorenew_black_24dp);
st.spinIconAnimation();  
st.setAlpha(StyleableToast.MAX_VISIBILTY);
st.show();

You could do something like

new StyleableToast(this, "Example", Toast.LENGTH_SHORT)
	.setBackgroundColor(Color.parseColor("#ff5a5f"))
	.setTextColor(Color.WHITE)
	.setIcon(R.drawable.ic_autorenew_black_24dp)
	.spinIconAnimation()
	.setAlpha(StyleableToast.MAX_VISIBILITY)
	.show();

Gravity

Is possible to set toast gravity???

How to clase StyleableToast ?

I'm make a toast that's appear when user scan a QR code , For some reasons toast can show more times. I need to close it or hide it when the user leave the scanning activity.
Thanks In advance

Fonts in Xml styles not working with API 26 xml Fonts

when using style.xml, font attribute does't work with api 26 font xml font system.

<style name="toastStyle">
    <item name="textFont">@font/inconsolata</item>
</style>

i'm still able to change it in code using .typeface(ResourcesCompat.getFont(context, R.font.inconsolata)) with the builder.
am i missing something?

Can't find 2.2.2

Hello,
I can't find 2.2.2 binary.
Can you deploy 2.2.2 version to any mvn repository, please?

Thank you

Drawable as Background

Since StyleableToast is a LinearLayout, shouldnt it be possible to set the background drawable, e.g. to a gradient like this ?

toast.setBackground(getApplicationContext().getDrawable(R.drawable.gradient));

or

toast.setBackgroundResource(R.drawable.gradient);

'tools:replace="android:appComponentFactory"'

Hello Muddz,
Greetings. I'm trying to use your tool in my project with Android 9, but I cannot because exist a conflict between your tool and my SDK version. What can I do?

Thank you.
Sincerely, Kevin.

Protected instead of private?

I would like to be able to extend your class and add some methods to modify specific behavior or attributes of some elements. In my case I need to change the gravity of the toast (toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);). Is there any way to do that?
I think would need to have access at least to the getToastLayout() method. For now I will probably try to copy your entire class into my project, but I think it would be good to have more flexibility, wouldn't it?

README Misspell

Support for the new Android Toast in API >=27 (Oero)

Is Oreo not Oero.

Toast style

There aren't any impact the android:layout_height, android:layout_width, android:padding. How to set them?

Icon padding Problem in RTL Languages

Hi,
In RTL Languages (Hebrew,Arabic,Persian,...) there is a bug with icon,relative positioning is working and the icon goes to the right side(which is a valid behavior) ,but when it goes to the right side of the Toast there is no padding for the icon and icon sticking to the edge of the right side of the toast.

Good work,your library is the best!

the icon is blurry

Hi , i use 2.1.2 change the iconStart

  1. icon size need to be designed?
    2.How to put toast at the bottom ?

image

Support custom duration

One of the biggest limitations with regular Toasts is the limited duration time (Only two states available). As far as I can see, this could be easily fixed in this library by allowing other durations in the withDuration() method (for the builder).

public StyleableToast.Builder withDuration(int duration) {
    if(duration == 1 || duration == 0) {
        this.length = duration;
    }

    return this;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.