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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:37:17+00:00 2026-06-17T02:37:17+00:00

I know this is a simple question, so hopefully it won’t be a bother

  • 0

I know this is a simple question, so hopefully it won’t be a bother to anyone.

How can I have a constant float value in my project that I can access from a View‘s XML and .java file?

I’ve tried setting a float value in my View‘s resource file as such:

<attr name="cornerRadius" format="float">15.0dp</attr>

I believe thats how it should be done, but I just did it using intuition. I’m really struggling on what to google on this subject.

Now, for accessing it in Java, I’ve tried this:

float myFloat = getContext().obtainStyledAttributes(attrs, R.styleable.MyView).getFloat(R.styleable.MyView_cornerRadius, 0.0f);

This is throwing me off, since its not getting the right value, but rather the value that I pass in the function. Why am I passing a float value to this function? There must be a different option.

Now, where the biggest problem is for me is accessing it in the XML.. I’ve tried this:

<corners android:radius="@attrs_my_view/cornerRadius"/>

I also tried this:

<corners android:radius="@float/cornerRadius"/>

But to no avail.

Maybe all of this is completely wrong, but I don’t know how to search for this in google, because I don’t know what its called. Its like having to look up a word in a dictionary based on its meaning. Its not a good time.

  • 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-17T02:37:19+00:00Added an answer on June 17, 2026 at 2:37 am

    You can create an XML file to contain your constants. This sounds like a dimension, which are standardly stored in the dimens.xml file. Place this in your res/values folder.

    So, you might have a file (named dimens.xml), with the following in it:

    <resources>
        <dimen name="cornerRadius">15dp</dimen>
    
    </resources>
    

    Then you can reference it using the normal R.class (ie. R.dimen.cornerRadius) – which you can reference from XML or Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is, hopefully, a simple question: First, I would like to know if anyone
I know this is a simple question for someone out there, but I have
I know this is a simple question, but I can't figure it out. Consider
I have a quick and hopefully simple question that I hope someone can help
Hi I have a simple question using html and css... hopefully someone can help
i have a (hopefully) simple question: Can i modify a xml file located in
Hopefully this question has a simple answer i'm overlooking! I have an IIS webserver
I know this is a simple question, but I thought I'd give it a
I know this is a simple question, but either nobody is explaining it right,
I know this is a simple question, but I am new to ASP MVC

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.