I have activity. Let them say A
it is defined in this appendix and corresponds to the relevant manifest. This activity loads content that it simply loads through the static index R. Let's say R.layout.foo. There is a component in this layout that looks at what is not a basic android. I see that when the Test application launches this action, the theme and styles within the theme are not filled with anything.
Manifest example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foo.bar"
android:versionCode="1"
android:versionName="Test"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:description="@string/description"
android:theme="@style/Theme.Custom"
android:name=".MyApplicationObject">
<activity android:name=".activity.A"/>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
</manifest>
Activity A
public class A extends Activity {
public void onCreate(Bundle a) {
setContentView(R.layout.foo);
}
}
Layout, foo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.foo.bar.CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Customview
public class CustomView extends RelativeLayout {
public CustomView(Context context, AttributeSet set) {
this(context, set, R.attr.CustomViewStyle);
}
public CustomView(Context c, AttributeSet set, int defStyle) {
super(c, set, defStyle);
TypedArray array = c.obtainStyledAttributes(set, R.styleable.CustomViewAttrs, defStyle, defStyle);
final int layout = array.getResourceId(R.styleable.CustomViewAttrs_layout, 0);
final Drawable icon = array.getDrawable(R.styleable.CustomViewAttrs_icon);
array.recycle();
if (layout == null) {
throw new IllegalStateException("WTF");
}
if (icon == null) {
throw new IllegalStateException("For real, WTF");
}
}
}
Some resources in the value file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomTypes">
<attr name="CustomViewStyle" format="reference"/>
</declare-styleable>
<declare-styleable name="CustomViewAttrs">
<attr name="layout" format="reference"/>
<attr name="anotherOne" format="reference"/>
</declare-styleable>
<style name="CustomView">
<item name="layout">@layout/foo</item>
<item name="AnotherOne">@drawable/icon</item>
</style>
<style name="Theme.Custom" parent="android:Theme">
<item name="CustomViewStyle">@style/CustomView</item>
</style>
<resources>
This works fine, but when I use ActivityUnitTest to load an instance of A, the values inside TypedArray are empty.
Some test classes
public class ActivityTester extends ActivityUnitTestCase<A> {
public ActivityTester() {
super(A.class);
}
public void testOne() {
Intent intent = new Intent(getInstrumentation().getTargetContext(), A.class);
startActivity(intent, null, null);
}
}
, / , ? , . startActivity() , , context.startActivity(). , , , , .