如何使用ActionBarActivity与Theme.Material [英] How to use ActionBarActivity with Theme.Material

查看:113
本文介绍了如何使用ActionBarActivity与Theme.Material的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建针对第l preVIEW一个新的项目。该SDK生成的启动活动来延长ActionBarActivity,但是,当我尝试运行裸骨生成的活动,它抛出以下异常:

 致:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题(或后代)与本次活动。
            在android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
            在android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
            在android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
 

我环顾四周,但 Theme.AppCompat.Material 似乎并不存在。我如何ActionBarActivity采取的新材料主题的优势呢?

我的build.gradle:

 应用插件:com.android.application

安卓{
    compileSdkVersion机器人-L'
    buildToolsVersion '20 .0.0
    defaultConfig {
        的applicationIDcom.sdchang.example
        的minSdkVersion'L'
        targetSdkVersion'L'
        版本code 1
        VERSIONNAME'1.0'
    }
    buildTypes {
        推出 {
            runProguard假
            proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'proguard-rules.pro
        }
    }
    productFlavors {
    }
}

依赖{
    编译文件树(导演:库,包括:['的* .jar'])
    编译com.android.support:appcompat-v7:21.+
    编译com.mcxiaoke.volley:图书馆:1.0 + @ AAR
    编译com.google code.gson:GSON:2.2 +
    编译com.squareup.okhttp:okhttp:2.0 +。
}
 

解决方案

AppCompat V21 +的 Theme.AppCompat 扩展 Theme.Base。 AppCompat 延伸 Theme.Platform.AppCompat 延伸安卓Theme.Material 21 +设备(如安卓L)的设备,所以你不应该做具体的,如果你使用的是AppCompat获得材料主题的东西。

I created a new project targeting the L preview. The starter activity that the sdk generates extends ActionBarActivity, however, when I try to run the bare-bone generated activity, it throws the following exception:

  Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
            at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)

I've looked around but Theme.AppCompat.Material doesn't seem to exist. How do I make ActionBarActivity to take advantage of the new Material themes?

My build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.sdchang.example'
        minSdkVersion 'L'
        targetSdkVersion 'L'
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.mcxiaoke.volley:library:1.0.+@aar'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.squareup.okhttp:okhttp:2.0.+'
}

解决方案

AppCompat v21.+'s Theme.AppCompat extends Theme.Base.AppCompat which extends Theme.Platform.AppCompat which extends android:Theme.Material on 21+ devices (i.e., Android L) devices so you shouldn't have to do anything specific to get the Material theme if you are using AppCompat.

这篇关于如何使用ActionBarActivity与Theme.Material的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆