0

I'm trying to build an app and want to show error if someone didn't fill-up the form correctly. Can I change the style of each component in Android Studio using java to highlight the component.

What I've done so far is this:

1. in styles.xml file, I did declare a new style name errorstyle as following:

<style name="errorstyle" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColor">#f45c42</item>
</style>

2. secondly in java file I did try to use following code.

selectedDate.setTextAppearance(this, android.R.style.errorstyle);

And it gives me an error message in java file:

cannot resolve symbol 'errorstyle'

Any suggestions?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rajind Pamoda
  • 143
  • 2
  • 10
  • Possible duplicate of [Design Android EditText to show error message as described by google](https://stackoverflow.com/questions/30953449/design-android-edittext-to-show-error-message-as-described-by-google) – Michael Dodd Mar 16 '18 at 14:20

3 Answers3

0

cannot resolve symbol 'errorstyle'

<style name="errorstyle" parent="Theme.AppCompat.Light.DarkActionBar">

Style errorstyle in your style section, So don't call android.R. Use R.style instead.

Do

selectedDate.setTextAppearance(R.style.errorstyle); 

FYI

setTextAppearance(Context context, int resId)

This method was deprecated in API level 23.

Use setTextAppearance(int) instead.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You should use R.style.errorstyle instead of android.R.style.errorstyle. Resources in android.R.* are coming from Android, resources created by you is in R.*.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
0

Use R.style.errorstyle instead of R.android.style.errorstyle. Sometimes it takes a while for Android Studio to recognize a style that you may have override. Try rebuilding the project or invalidate cache and restart android studio.

sanjeev
  • 1,664
  • 19
  • 35