Action bar size in custom xml file

I cannot find a way to insert the action bar size attribute into my own XML file. Since I am using google maps in my activity, I cannot use the inline xml attribute at all in my layout, but I have to name setPadding()

in the map using the size of the action bar. Now I have found a way to get the actionBarSize at runtime, but I wonder if I can skip this code entirely by inserting the android attribute into my onw xml, like so:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <dimen name="myownsize">@android:attr/actionBarSize</dimen>

</resources>

      

But it doesn't work that way. Is there a way to do this?

+3


source to share


1 answer


Define attr

in your own project. Create res/values/attrs.xml

and add the following:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <attr name="myownsize" format="dimension"></attr>

</resources>

      

In yours res/values/styles.xml

, according to the parent theme's definition, initialize this attribute:

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="myownsize">?android:attr/actionBarSize</item>
</style>

      



Once this is done, you can use ?attr/myownsize

as a measurement:

android:padding="?attr/myownsize"

      

Sorry if I misunderstood the question too.

+3


source







All Articles