1

I would like to create a TextView which displays current application version.

Is it possible to use manifest data (in this case versionName attribute) in XML resource file to achieve this?

<TextView
    android:layout_width = "fill_parent"
    android:layout_height = "wrap_content"

    android:text = "(VERSION NAME)"
/>
2

1 Answer 1

0

I have not tested but try this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="?android:attr/versionName"
     />
    <!-- or -->
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="?android:attr/versionCode"
     />

If it doesnt the only solution is to use it programmatically

context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;

or use data from strings.xml in AndroidMainfest.xml file.

1
  • Read that topic. I think no more solutions to do it in resources.
    – Vyacheslav
    Commented Sep 26, 2015 at 10:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.