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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:29:24+00:00 2026-06-09T11:29:24+00:00

I have an XML file with 5 textviews, all with the same textSize. Currently,

  • 0

I have an XML file with 5 textviews, all with the same textSize. Currently, I define the size like this:

android:textSize="30dp"

However, I want a quick way to apply something like:

android:textSize="text_size"

Where textSize would be a variable I define somewhere, and can use wherever I want in my XML file. I tried defining these variables in the strings.xml file in the Android project, and calling them like this:

android:textSize="@string/text_size"

Where it would be defined like this in strings.xml

<string name="text_size">30dp</string>

It worked fine in Ecplise itself, and showed just fine in the Graphic Layout. But when I tried running the app on my phone, it crashed.

So, is there a way to define variables in my XML layout files? Thanks.

  • 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-09T11:29:26+00:00Added an answer on June 9, 2026 at 11:29 am

    Your idea of putting it in strings.xml is close, but those values need to be set in a dimensions XML file. The documentation is here.

    Using your example, you might make a file called res/values/my_dimens.xml. Then put in there

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <dimen name="my_text_size">30dp</dimen>
    </resources>
    

    Then to use it in your layout, just set

    android:textSize="@dimen/my_text_size"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi to all, i have written something like this in the xml file <?xml
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have an xml file like this. On vertical orietation everything is looking perfect.
I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I'm dynamically generating a layout, and to do this I have a menu_row_element.xml file
I need to use same widgets(buttons,editext,textviews) with same properties like width,height,textColor,size etc in multiple
I have a layout like this in xml format. But I need to do
All, I have the following in my string resource xml file. <?xml version=1.0 encoding=utf-8?>

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.