不能使用ActionBarActivity与Theme.Material [英] cant use ActionBarActivity with Theme.Material
问题描述
每当我在模拟器扩展与ActionBarActivity它生成的类和欠幅脉冲时间错误,当我使用的主题为Theme.Material ...在风格。当我改变这一主题,以应用程序兼容性它工作正常。
或者即使我的ActionBarActivity更改到活动的主题为Theme.Material那么也能正常工作的棒棒糖模拟器。
Whenever I extend the class with ActionBarActivity it generates and runt time error on the emulator when I am using the theme as Theme.Material... in the styles. When I change this theme to AppCompat it works fine. Or Even If i change the ActionBarActivity to Activity with the theme as Theme.Material then also it works fine on the lolipop emulator.
款式/价值观v1.xml
styles/values-v1.xml
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:colorPrimaryDark">#3F51B5</item>
<item name="android:colorPrimary">#3031B5</item>
</style>
<style name="ActionBarTheme" parent="android:ThemeOverlay.Material.ActionBar">
<item name="android:textColorPrimary">#f00</item>
<item name="android:textColorSecondary">#00f</item>
</style>
MainActivity.class
MainActivity.class
package com.example.sharmakritya.myapplication;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=(Toolbar)findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if(id==R.id.next){
}
return super.onOptionsItemSelected(item);
}
}
的build.gradle:
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.sharmakritya.myapplication"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:21.0.3"
}
我想使用的动作条上的棒棒糖材质的主题。我在做什么错在这里?
I want to use the ActionBar with the Material theme on the lolipop. What am I doing wrong here ?
推荐答案
如果你想使用 Theme.Material
在Android 5.0以上版本,那些使用该主题活动的需要要使用本机操作栏日常活动,你将需要有一些其他的主题是基于关闭的 Theme.Holo
。
If you want to use Theme.Material
on Android 5.0+, those activities that use that theme need to be ordinary activities using the native action bar, and you will need to have some other theme for older devices that is based off of Theme.Holo
.
如果你想使用 ActionBarActivity
从应用程序兼容性-V7
,你必须使用 Theme.AppCompat
为你的主题的基础上,并依靠它来给你新老装置的材料设计十岁上下。
If you want to use ActionBarActivity
from appcompat-v7
, you have to use Theme.AppCompat
as the basis for your theme, and rely upon it to give you a Material Design-ish on old and new devices.
因此,要回顾一下:
So, to recap:
-
Theme.Material
要求本地操作栏 - 在
应用程序兼容性-V7
动作条反向移植不能使用Theme.Material
Theme.Material
requires the native action bar- the
appcompat-v7
action bar backport cannot useTheme.Material
这篇关于不能使用ActionBarActivity与Theme.Material的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!