我使用Android studio 3.1.2。我收到此错误消息。我该如何解决这个问题?
错误:找不到符号this.setSupportActionBar(toolbar);
我的应用build.gradle
apply plugin: 'com.android.application'
compileSdkVersion 27
buildToolsVersion '28.0.0 rc1'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.XXXX.XXXX"
manifestPlaceholders = [onesignal_app_id : "9dfhdfg-art455-3455-8dfgh45-fghe345340fh45",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "REMOTE"]
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
flavorDimensions "default"
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
dimension "default"
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 16
dimension "default"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'it.neokree:MaterialTabs:0.11'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation files('libs/picasso-2.4.0.jar')
implementation 'de.hdodenhof:circleimageview:1.3.0'
implementation 'com.onesignal:OneSignal:3.+@aar'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.android.gms:play-services-analytics:15.0.0'
implementation 'com.android.support:gridlayout-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
我的错误Java页面:
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
public class CategoryItem extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.category_item_grid);
toolbar = (Toolbar) this.findViewById(R.id.toolbar);
toolbar.setTitle(Constant.CATEGORY_TITLE);
this.setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
它还会显示以下错误消息:
无法解决methed'setSupportAcationBar'import android.support.v7.widget.Toolbar;
我该如何解决?什么是贬值?任何一个人
答案 0 :(得分:0)
使用AppCompatActivity
代替ActionBarActivity