Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8452159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:25:49+00:00 2026-06-10T11:25:49+00:00

I have a layout that I use for rows in a ListView . In

  • 0

I have a layout that I use for rows in a ListView. In some places, I need to show the layout in a ‘light’ style and in some places ‘dark’. How can I accomplish this using Android styles, themes, etc?

I understand the concept of styles, but it seems like they’re only for a single element. They let me define a set of properties that are applied to the element with the style. What I’d like to do is define the following properties:

  • Title text color (applied to TextView 1)
  • Subtitle text color (applied to TextView 2)
  • Background (applied to the parent layout)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:25:50+00:00Added an answer on June 10, 2026 at 11:25 am

    It’s not possible to set a style programatically, so I’m creating a theme and this theme is applied to the activities where it’s needed.

    Create attributes

    Add the styleable attributes to res/values/attrs.xml like so:

    <declare-styleable name="MyTheme">
        <attr name="titleColor" format="color" />
        <attr name="subtitleColor" format="color" />
        <attr name="backgroundDrawable" format="reference" />
    </declare-styleable>
    

    MyTheme doesn’t seem to need to relate to anything. I suspect it’s just a namespace for the attributes.

    Create style

    In res/values/styles.xml:

    <style name="MyTheme.LightRows">
        <item name="titleColor">@color/black</item>
        <item name="subtitleColor">@color/grey</item>
        <item name="backgroundDrawable">@drawable/cell_bg</item>
    </style>
    

    Apply style to activity

    In AndroidManifest.xml:

    <activity android:name=".view.activity.LightActivity" 
              android:theme="@style/MyTheme.LightRows" />
    

    Reference style attributes

    In the layout used for the list row (or whatever):

     android:textColor="?attr/titleColor"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can a have a ListView that has different amount of rows? Instead of
I have a page layout that I use in my SharePoint solution when I
So I have a table layout that Im adding rows to through code since
I have a ListView that I want to use with an ArrayAdapter to add
I am developing an app in which I need a ListView whose rows have
I have a BaseAdapter that manages the rows in my ListView . All this
I have this layout that works correctly, a relative layout with a text view
I have a layout that contains two ImageViews. I want one of them to
So I have a layout that is a separate file, so I inflate it.
Simple - I have a layout that is 800 by 600. When I press

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.