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 9003909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:46:43+00:00 2026-06-16T00:46:43+00:00

Currently I’m using either a WebView or a TextView to show some dynamic data

  • 0

Currently I’m using either a WebView or a TextView to show some dynamic data coming from a webservice in one of my apps.
If the data contains pure text, it uses the TextView and applies a style from styles.xml.
If the data contains HTML (mostly text and images) it uses the WebView.

However, this WebView is unstyled. Therefor it looks a lot different from the usual TextView.
I’ve read that it’s possible to style the text in a WebView simply by inserting some HTML directly into the data. This sounds easy enough, but I would like to use the data from my Styles.xml as the values required in this HTML so I won’t need to change the colors et cetera on two locations if I change my styles.

So, how would I be able to do this? I’ve done some extensive searching but I have found no way of actually retrieving the different style attributes from your styles.xml. Am I missing something here or is it really not possible to retrieve these values?

The style I’m trying to get the data from is the following:

<style name="font4">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">#E3691B</item>
    <item name="android:paddingLeft">5dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:textStyle">bold</item>
</style>

I’m mainly interested in the textSize and textColor.

  • 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-16T00:46:44+00:00Added an answer on June 16, 2026 at 12:46 am

    It is possible to retrieve custom styles from styles.xml programmatically.

    Define some arbitrary style in styles.xml:

    <style name="MyCustomStyle">
        <item name="android:textColor">#efefef</item>
        <item name="android:background">#ffffff</item>
        <item name="android:text">This is my text</item>
    </style>
    

    Now, retrieve the styles like this

    // The attributes you want retrieved
    int[] attrs = {android.R.attr.textColor, android.R.attr.background, android.R.attr.text};
    
    // Parse MyCustomStyle, using Context.obtainStyledAttributes()
    TypedArray ta = obtainStyledAttributes(R.style.MyCustomStyle, attrs);
    
    // Fetch the text from your style like this.     
    String text = ta.getString(2);
    
    // Fetching the colors defined in your style
    int textColor = ta.getColor(0, Color.BLACK);
    int backgroundColor = ta.getColor(1, Color.BLACK);
    
    // Do some logging to see if we have retrieved correct values
    Log.i("Retrieved text:", text);
    Log.i("Retrieved textColor as hex:", Integer.toHexString(textColor));
    Log.i("Retrieved background as hex:", Integer.toHexString(backgroundColor));
    
    // OH, and don't forget to recycle the TypedArray
    ta.recycle()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently we use log4net of version 1.2.10.0 and we should start using some 3rd
currently, I am using a SQLite database with some addresses and telephone numbers. All
Currently I am working in message compose screen in Android, Using Intent to show
I am currently running into a problem where an element is coming back from
Currently I'm using the Jackson JSON Processor to write preference data and whatnot to
Currently I am using HTML files for parts of my user interface. I display
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I'm trying to parse some html and return an array with the values
Currently we are using Trac . Tickets are good for tracking tasks and related

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.