#android #android-actionbar #android-support-library #android-actionbar-compat #android-actionbaractivity
#Android #android-actionbar #android-support-library #android-actionbar-compat #android-actionbaractivity
Вопрос:
Я использую Support Actionbar
. Он работает в MessageTemplateActivity
, потому что, когда я хочу показать обратно включить as getSupportActionBar().setDisplayHomeAsUpEnabled(true);
, он включает кнопку «Назад». Но в SyncActivity
, getSupportActionBar() is returning
null . Can anyone please tell me why in
SyncActivity` он возвращает значение null .
Исключение NullPointerException
06-17 18:45:45.327: E/AndroidRuntime(25335): Caused by: java.lang.NullPointerException
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.getDisplayOptions(ActionBarImplICS.java:234)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.<init>(ActionBarImplICS.java:57)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.<init>(ActionBarImplICS.java:46)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivityDelegateICS.createSupportActionBar(ActionBarActivityDelegateICS.java:46)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:83)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:66)
SyncActivity.java
public class SyncActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_sync_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
layout_sync_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@ id/mainSyncScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
MessageTemplateActivity.java
public class MessageTemplateActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_message_template);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
макет.layout_message_template.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@ id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
Спасибо,