Android Studio 0.4.5
用于创建自定义对话框的Android文档:http://developer.android.com/guide/topics/ui/dialogs.html
如果需要自定义对话框,则可以将"活动"显示为对话框,而不是使用"对话框API".只需创建一个活动并将其主题设置为<activity>清单元素中的Theme.Holo.Dialog :
<activity android:theme="@android:style/Theme.Holo.Dialog" >
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个时,我得到以下异常:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
Run Code Online (Sandbox Code Playgroud)
我支持以下内容,我不能使用大于10的内容:
minSdkVersion 10
targetSdkVersion 19
Run Code Online (Sandbox Code Playgroud)
在我的风格中,我有以下内容:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
在我的清单中,我有这个活动:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@android:style/Theme.Holo.Light.Dialog"
android:name="com.ssd.register.Dialog_update"
android:label="@string/title_activity_dialog_update" >
</activity>
Run Code Online (Sandbox Code Playgroud)
像我这样创建对话框是我要做的事情,因为我已经完成了布局.
谁能告诉我如何解决这个问题?
我得到在Android 2.3.5一个RuntimeException,但我正在用Theme.AppCompat(RES /价值/的themes.xml).这是电话:http://www.gsmarena.com/samsung_galaxy_y_s5360-4117.php
<!-- res/values/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="@style/Theme.AppCompat">
<item name="actionBarStyle">@style/QueryActionBar</item>
<item name="android:actionBarStyle">@style/QueryActionBar</item>
</style>
<style name="QueryActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@color/blueback</item>
<item name="android:background">@color/blueback</item>
<item name="backgroundSplit">@color/blueback</item>
<item name="android:backgroundSplit">@color/blueback</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是values-v11的文件.
<!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="QueryTheme" parent="@android:style/Theme.Holo">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是错误.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txt2lrn.www/com.txt2lrn.www.LandingActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with …Run Code Online (Sandbox Code Playgroud) 我有一个显示"Hello World"的Android项目.它是从Android Studio的"空白活动"模板创建的.
然后我在我的应用程序包中添加/创建一个新的java类(与我的活动相同的包).我称之为Shape并添加一个简单的构造函数
public class Shape {
public Shape(int i){
if (i==0){
throw new IllegalArgumentException("Cant have 0");
}
}
}
Run Code Online (Sandbox Code Playgroud)
大.现在我有一个完全没有触及Android的课程,我想对它进行单元测试.接下来我该怎么办?
这是我的问题停止的地方.下面我将介绍我尝试过的内容.


我写了我的考试
package com.eghdk.getjunit4towork;
import org.junit.Test;
import static org.junit.Assert.*;
public class ShapeTest {
@Test(expected = IllegalArgumentException.class)
public void testShapeWithInvalidArg() {
new Shape(0);
}
}
Run Code Online (Sandbox Code Playgroud)此时,我不确定如何运行我的测试,但尝试这样做:

我跑步时遇到这些错误
错误:(3,17)Gradle:错误:包org.junit不存在
错误:(5,24)Gradle:错误:包org.junit不存在
错误:(8,6)Gradle:错误:找不到符号课堂考试
我尝试测试一个使用ActionBarActivity的Activity(来自appcompat库).我需要一个自定义应用程序才能操作DI系统来加载我的测试服务而不是真正的服务.
如果我编写了测试并调用startActivity,我会收到以下错误:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Run Code Online (Sandbox Code Playgroud)
如果我调用launchActivityWithIntent,Activity会启动而没有任何问题,但它使用的是我的Real Application类而不是Mocked Application类.任何想法如何解决这个问题或如何在应用程序的onCreate之后执行代码,但是在我的仪器测试中调用onCreate of my Activity之前?
android unit-testing android-activity android-actionbar android-actionbar-compat