With setTextColor() method we can set the color for Textview.
For this method we need to pass color vallu
Textview has property 'textColor' attribute which is set a color of our choice. We can provide the color as hexa value in one of the four formats: rgb, argb, rrggbb, or aarrggbb. The syntax to set textColor attribute for TextView using different color formats is ... android:textColor="#92B" /> ... android:textColor="#A92B" /> ... android:textColor="#9C27B0" /> ... android:textColor="#CC9C27B0" /> Example 1 – TextView Color Let us create an Android application with Kotlin support in Android Studio and change the text color of TextView in XML layout file. activity_main.xml
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linear_layout_id" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> android:id="@+id/text_view_id" android:layout_height="wrap_content" android:layout_width="match_parent" android:gravity="center" android:textSize="40dp" android:padding="50dp" android:textColor="#9C27B0" android:text="@string/hello" />
We have used a string resource, and the contents of strings.xml is
There is no need to change the MainActivity.kt file. The default code would do.
MainActivity. import androidx.appcompat.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
textView.setTextColor(Color.parseColor("#ffffff"));textView.setTextColor(Color.rgb(200,0,0));textView.setTextColot(ContextCompat.getColor(context, R.color.your_color);)Change Text Color of TextView via XML Layout File
Permission denied for window type 2010 in Marshmallow device
How do I check in SQLite whether a table exists?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is "shared preferences" in Android ?
How to convert milli seconds to hours, minutes and seconds in Android?
What is ANR in android?
How to Exit android app on back pressed?
How to get complete address from latitude and longitude?
How to reduce APK package size?
What is Android?
Open PDF in Google Drive with Intent in Android - RRutors
How to find Android Device UDID or unique ID?
How To Set Text Color Programmatically Android TextView?
What is ANR? How to avoid and resolve it?
How to start a new activity on button click
How to Generate signed apk with android studio
How to Use Deprecated Handler() in Android - RRutors Guide
Decompile APK Files: How to Get Source Code - RRutors Guide
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Application?
How to validate email address in Android with Kotlin?
How to install/ uninstall apk by command line ADB
What is NetworkOnMainThread Exception?
What are Android Versions available?
Add Jar/Library Files as Dependency in Android Studio
Fix Play Store Rejection Due to SMS Permission - RRutors
How to get a contact image using a phone number in android?
How to avoid multiple button click at same time in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Key Points to remember while develop the Android Application.
Extract Date and Time from Long Type Variable - RRutors
How to convert DP to Pixel and Pixel to Dp?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Check List for Generate Signed APK Android
How to check Android version?
How do i load image from drawable folder in Jetpack Compose?
What is the difference between match_parent and fill_parent?
How to get screen size (width,height) in Android?
What are the notifications available in android?