我看到不推荐使用ActionBarActivity。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Put the home button as an icon, without being an 'up' button and without title text
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
inflater.inflate(R.menu.template, menu); // Inflate the menu; this adds items to the action bar if it is present.
// tell the main activities view pager to enable paging
mViewPagerListener.SetViewPagerPagingEnabled(true);
super.onCreateOptionsMenu(menu, inflater);
}
我今天应该做什么?我个人在设备上进行测试时没有看到异常,但希望解决此问题以完成操作。在AndroidStudio中突出显示为黄色并返回警告。我该怎么办?
建立以供参考:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.test.app"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.ogaclejapan.smarttablayout:library:1.5.0@aar'
compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
compile 'com.android.support:appcompat-v7:23.1.1'
// recyclerview
compile 'com.android.support:recyclerview-v7:23.1.1'
// google analytics
compile 'com.google.android.gms:play-services-analytics:8.3.0'
// pager sliding strip
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
// http library (for using beanstream REST)
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
// amaazon S3 uploads
compile 'com.amazonaws:aws-android-sdk-s3:2.1.+'
// paypal purchasing
compile files('libs/PayPalAndroidSDK-2.7.1.jar')
// Module dependency on ParseLoginUI library sources
compile project(':ParseLoginUI')
// Parse libs
compile files('libs/ParseCrashReporting-1.9.2.jar')
compile files('libs/Parse-1.9.1.jar')
compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')
// android support v4
compile files('libs/android-support-v4.jar')
// facebook SDK
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
//butterknife
compile 'com.jakewharton:butterknife:6.1.0'
// Subsampling-scale-image-view (for templating)
//compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
compile files('libs/AppRater.jar')
}
最佳答案
从大约1年以来不推荐使用ActionBarActivity
。它的自然替代物是AppCompatActivity
。要使用它,您需要添加
compile 'com.android.support:appcompat-v7:23.1.0'
作为您
build.gradle
中的依赖项。如果您的主题是不带
getSupportActionBar()
的主题,则ActionBar
返回null。如果您将主题与ActionBar
一起使用,或者正在使用ToolBar
,则可以忽略该警告。如果您想确保针对NPE进行检查 final ActionBar actionBar;
if (getActivity() != null && (actionBar = getActivity().getSupportActionBar()) != null) {
actionBar.setDisplayShowTitleEnabled(false);
}