I try to refer to ?attr/actionBarSize in dimens.xml in two ways:
<dimen name="bottom_margin">?attr/actionBarSize</dimen>
<dimen name="bottom_margin">#attr/actionBarSize</dimen>
The first one is compiling but I get runtime error from inflanter:
RuntimeException: Unable to resume activity {pl.example/pl.example.ui.gui.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
So question is: how to refer to that value?
Next I will use this value in animator or use from code.
Actually I don't see if there is a sense to declare own dimensions if it already declared in theme, so it would be better to use ?attr/actionBarSize directly where you need that.
But if you really need it for some reason try as following:
<dimen name="bottom_margin">?actionBarSize</dimen>
The correct syntax is:
?android:attr/actionBarSize
Use it like this with android key.
android:layout_width="?android:actionBarSize"
Related
I have some problem with setting params to my view in xml file with values from dimen files.
For example when i'm adding layout_height param to my EditText in laytout xml file:
<EditText
....
android:layout_height="#dimen/et_height"
....
/>
File dimens:
<resources>
.........
<dimen name="example">16dp</dimen>
<dimen name="et_height">20dp</dimen>
.........
</resources>
It works fine. But sometimes when i open this file again AndroidStudio replace #dimen/et_height with value 20dp in layout xml file. And i must change it again to #dimen/et_height.
How can i fix this ?
This is the normal case:
But in my case AndroidStudio replaces with value:
Having the same issue. Thought it is the ConstraintLayout but the issue also appears in every other layout though..
related post from me :
Android ConstraintLayout #dimens replaced with hardcoded values
Also some other user said it just shows the dp value, i am completely in your situation i know the grey text, but it does really replace the value..
I have dozens of ImageViews in my xml file and defined the length in strings.xml such as string name="cardWidth">100dp</string> and then had content_main.xml use that string in the width. Like android:layout_width="#string/cardWidth" that way I could just change the value once and see how all the images displayed.
No problems with the compile but got a run time error
Binary XML file line #XX:
You must supply a layout_width attribute.
I researched and I saw in S.O. that this will occur when you use a string in the value. I'll probably just hard code the value once I'm happy with it but is there a way around this?
Thanks!
Sorry for the formatting, it's my first question here!
Your dimension values need to be defined as (possibly in a file res/values/dimens.xml):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cardWidth">100dp</dimen>
</resources>
Then, you can access them using:
android:layout_width="#dimen/cardWidth"
use these width with dimensions in values folder not with string.xml like below :
<dimen name="cardWidth">16dp</dimen>
Hi
I am facing a problem
I want my application to pick up resources from the framework. Here is my code snippet of an xml.
For this to be achieved following changes were made in attrs.xml
and themes.xml at the framework level
#android:drawable/btn_minus_ss
The drawable btn_minus_ss.png is added to drawable-hdpi folder at the location framework/base/core/res/res/drawable-hdpi
Whenever I open the application, it crashes.
I get the following error in logs
ERROR/AndroidRuntime(3701): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: tag requires a 'drawable' attribute or child tag defining a drawable
However, when I use this
android:background="?android:attr/theme_btn_minus_ss"
I don't get any error. I want to use
android:drawable
What is the cause and how can this problem be solved.
Thanks & Regards
Aviral
The error
ERROR/AndroidRuntime(3701): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: tag requires a 'drawable' attribute or child tag defining a drawable
has to do with the format of your xml, you are setting something like
<item android:background="#foo-value-here" />
What the error is telling you is that it should be like this
<item android:drawable="#foo-value-here" />
i think i had the same problem, it seems to be a bug in the android eclipse-plugin. the solution is the same as for this question (close eclipse and restart it): android include tag - invalid layout reference
Also make android:drawable the first attribute of item tag - it worked for me.
"java.lang.RuntimeException: Unable to start activity ComponentInfo : android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout"
I am getting this error can anyone help me?
We'd need a little more of your output to know for sure but my bet is your layout is lacking either layout_width or layout_height. Can you please post a little more extended context for your exceptions (a few lines before, a few lines after the line you already posted) ?
Same problem i faced,
At one of my inflate view i getting "android.view.InflateException", because
i am using image of 1200x1200. I conveted it to 100x100 and now it working.
You may try removing tags like android:divider in the XML file.
Looking in the android sdk folders, I've found a file called values/config.xml. This seems to be somewhere that you can define values for later use in layouts and animations.
Given the config.xml:
<resources>
<string name="config_somePadding">50dip</string>
</resources>
How would I reference this to use as the layout_height in a layout xml file?
#string/config_somePadding is actually the only one I've found that doesn't throw an error in Eclipse (even though there isn't a config_somePadding in values/strings.xml), but it appears to just put an empty string.
In the sdk, they use an integer for animation duration. They reference it like this: android:duration="#android:integer/config_longAnimTime". Is there a way to use values that aren't integers in the layout_height attribute?
How would I reference this to use as
the layout_height in a layout xml
file?
You wouldn't. Use a dimension resource instead.
Is there a way to use values that
aren't integers in the layout_height
attribute?
You have to use a dimension resource for dimensions.