Feed Buzzard
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
Feed Buzzard
No Result
View All Result
Home World Tech

Android: How to set the colour of a Toast’s text –

Gordon James by Gordon James
January 3, 2021
in World Tech
0
0
SHARES
138
VIEWS
Share on FacebookShare on Twitter

Development issue/problem:

I display the toast message as a result of the if declaration with the following code :

Toast.makeText(getBaseContext(), Enter the Price, Toast.LENGTH_SHORT).show() ;

It appears as a white text on a white background, so unreadable! My question is: how can I change the colour of the toast text?

How can I solve this problem?

Solution 1:

You can make your own kind of toast according to your needs. See Making a custom toast at http://developer.android.com/guide/topics/ui/notifiers/toasts.html.

Solution 2:

You can do this very easily without creating your own layout by using the standard Toast:

ToastToast = Toast.makeText(dit, resId, Toast.LENGTH_SHORT);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
v.setTextColor(Color.RED);
toast.show() ;

The default presentation of the Toast view is in the Android SDK :

$ANDROID-SDK$/platform/android-8/data/res/lay-out/transient_notification.xml

Solution 3:

You can make your own toast

–

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root))

ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(Hello! This is your toast!)

Toast toast = new Toast(getApplicationContext()) ;
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0) ;
toast.setDuration(Toast.LENGTH_LONG) ;
toast.setView(layout) ;
toast.show() ;

Source:

Solution 4:

The easiest way to change the background colour of the toast and the background colour of the toast text:

View;
TextView text;
Toast;
toast.makeText(this, resId, Toast.LENGTH_SHORT);
view = toast.getView();
text = (TextView) view.findViewById(android.R.id.message);
text.setTextColor(getResources().getColor(R.color.black));
text.setShadowLayer(0,0,0,0,0);
view.setBackgroundResource(R.color.white);
toast.show() ;

Solution No 5:

You can also use SpannableString. It can also color parts of a rope.

SpannableString spanableString = new SpannableString(This is red text);
spannableString.setSpan(
new ForegroundColorSpan(getResources().getColor(android.R.color.holo_red_light))),
0,
SpannableString.length(),
0);
Toast.makeText(this, SpannableString, Toast.LENGTH_SHORT).show() ;

Solution No 6:

Try the Toasty Library. It is very easy to use – https://github.com/GrenderG/Toasty

Solution No 7:

You can try this if you don’t want to use custom libraries.

Toast=Toast.makeText(getApplicationContext(),This is extended toast,Toast.LENGTH_LONG);
view=toast.getView();
view textview1=(TextView)view.findViewById(android.R.id.message) ;
view1.setTextColor(Color.YELLOW) ;
view.setBackgroundResource(R.color.colorPrimary) ;
toast.show() ;

Solution No 8:

Here is an example in Kotlin that shows how to change the background colour of the toast and the colour of the text:

val toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)toast.view.background.setColorFilter(ContextCompatible.getColor(context,R.color.white), PorterDuff.Mode.SRC_IN)fall textView = toast.view.findViewById(android.R.id.message) as TextViewtextView.setTextColor(ContextCompat.getColor(context, R.color.black))toast.show())

Good luck!

Related Tags:

android toast default background color,toast background,how to change toast text size in android,android toast style,custom toast in android,toast gravity,toast getview deprecated,android toast font color,android toast bold text,android toast theme,how to set toast size in android

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Gordon James

Gordon James

James Gordon is a content manager for the website Feedbuzzard. He loves spending time in nature, and his favorite pastime is watching dogs play. He also enjoys watching sunsets, as the colors are always so soothing to him. James loves learning about new technology, and he is excited to be working on a website that covers this topic.

Related Posts

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics
World Tech

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics

December 15, 2022
World Tech

Rockstar Games Brings GTA to The Metaverse

October 20, 2022
World Tech

Ways Technology Is Changing The World Of Education

September 21, 2022
Next Post

Singapore Startup Ecosystem – Exclusive Year End Analysis – 2020

Microsoft Teams crash issues during launch

How to Protect Yourself from Increasing Malware Attacks During the Pandemic

No Result
View All Result

Recommended

Myths and Misconceptions About Joint Pain

Myths and Misconceptions About Joint Pain

6 hours ago
The Spider Veins Facts that Every Individual Ought to Know

The Spider Veins Facts that Every Individual Ought to Know

6 hours ago

5 Benefits of Telehealth That You Should Understand

16 hours ago
openai gpt3 dallmiddotdouglas mit technologyreview

Why GPT-3 is so Impressive – and Why it’s Also Worrying

24 hours ago

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

Recent Posts

  • Myths and Misconceptions About Joint Pain January 30, 2023
  • The Spider Veins Facts that Every Individual Ought to Know January 30, 2023
  • 5 Benefits of Telehealth That You Should Understand January 30, 2023
  • Why GPT-3 is so Impressive – and Why it’s Also Worrying January 29, 2023

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

© 2022 FeedBuzzard.com

No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT