MPol MPol - 10 days ago 5
Android Question

Progress Bar in Theme

I have been having problems with incorporating a Progress Bar into my splash screen. I have an XML file called splash_setup,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">

<bitmap
android:src="@drawable/splash"
android:tileMode="disabled"
android:gravity="top|center_horizontal" />

<ProgressBar
style="@android:style/Widget.ProgressBar.Small"
android:gravity="top|center_horizontal" />

</LinearLayout>


This file is used as background for 'splashTheme' (in Styles.XML) as following,

?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="splashTheme" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash_setup</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>


The splashTheme is used in splashActivity (the splash executes database initialisation and then finished),

[Activity(Label = "@string/appName", Theme = "@style/splashTheme",
MainLauncher = true, NoHistory = true)]


So to my problem... the splash_setup code runs fine without tags, but when they are in I get the following error,


android.content.res.Resources$NotFoundException: File res/drawable/splash_setup.xml from drawable resource ID #0x7f020002


Could anyone point out what I am doing wrong? Thanks!

Answer

What you have is a layout not a drawable. android:windowBackground attribute in style allows only drawable which may include shapes and/or layer lists. If you really wish to show a progressbar, then you need an activity.