Shoaib Anwar Shoaib Anwar -5 years ago 117
Android Question

Two textviews with different colors using one theme?

Im new to android and i have been trying to find out an answer to this. I have a layout file .xml for listview that has two textviews, one is for heading with a greater size and other below it for description. What i want is that heading textview's text stays white and description textview's text stays grey in my current theme. That is dark theme. But user has the option to change the theme, so when user selects Light theme i want my heading textview's text (that is within layout that i have for listview's rows) to become black and also the description textview's text to become black.
Please help and thanks in advance.

Answer Source

You can change theme programmatically. There is one guy asked this hours ago. Can you check this : how-to-change-colour-when-user-wants-another-colour-in-the-app

Also if you want to use diferent themes for different TextViews you can try like :


How i can create custom themes for TextView

in your styles.xml create different styles :

<style name="MyBlueTextTheme" parent="@android:style/TextAppearance.Medium"> 
    <item name="android:textSize">18sp</item> 
    <item name="android:textColor">#123456</item> 
    <item name="android:textStyle">bold</item>

Then use it like :

android:text="This is a blue styled text" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download