1

我在我的 android 应用程序的操作栏上启用了后退按钮,但这会引发错误

当我在 4.0 及更高版本的模拟器上运行时,我的 android 应用程序。

我能够使用可绘制的 new_indicator.xml 和我的样式表来创建它

我活动中的代码行。我会把它贴出来供你阅读。

new_indicator.xml

<?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:left="0dp"
        android:right="5dp">
        <bitmap android:src="@drawable/back" />
    </item>

</layer-list>


I would paste the block of my activity that as the error

actionBar = getSupportActionBar();



            ****actionBar.setDisplayHomeAsUpEnabled(true); //This line is the error Null pointer error ****

            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setIcon(android.R.color.transparent);

            super.onCreate(savedInstanceState);
            setContentView(com.example.rhemamedicare.R.layout.homeactivity);

            context = HomeActivity.this;            
            cd = new ConnectionDetector(context);


My style sheet is below

I believe there is some thing that I am missing in the style

<style name="Theme.Jcodestyle" parent="@style/Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarItemBackground">@drawable/selectable_background_jcodestyle</item>
        <item name="popupMenuStyle">@style/PopupMenu.Jcodestyle</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Jcodestyle</item>
        <item name="actionBarTabStyle">@style/ActionBarTabStyle.Jcodestyle</item>
        <item name="actionDropDownStyle">@style/DropDownNav.Jcodestyle</item>
        <item name="actionBarStyle">@style/ActionBar.Solid.Jcodestyle</item>
        <item name="actionModeBackground">@drawable/cab_background_top_jcodestyle</item>
        <item name="actionModeSplitBackground">@drawable/cab_background_bottom_jcodestyle</item>
        <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Jcodestyle</item>
        <item name="android:windowTitleSize">35dip</item>

        <item name="android:spinnerStyle">@style/holoSpinner</item>
        <item name="homeAsUpIndicator">@drawable/new_indicator</item>


        <!-- Light.DarkActionBar specific -->
        <item name="actionBarWidgetTheme">@style/Theme.Jcodestyle.Widget</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="ActionBar.Solid.Jcodestyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/ab_solid_jcodestyle</item>
        <item name="backgroundStacked">@drawable/ab_stacked_solid_jcodestyle</item>
        <item name="backgroundSplit">@drawable/ab_bottom_solid_jcodestyle</item>
        <item name="progressBarStyle">@style/ProgressBar.Jcodestyle</item>
    </style>

    <style name="ActionBar.Transparent.Jcodestyle" parent="@style/Widget.Sherlock.ActionBar">
        <item name="background">@drawable/ab_transparent_jcodestyle</item>
        <item name="progressBarStyle">@style/ProgressBar.Jcodestyle</item>
    </style>

    <style name="PopupMenu.Jcodestyle" parent="@style/Widget.Sherlock.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_jcodestyle</item>
    </style>

    <style name="DropDownListView.Jcodestyle" parent="@style/Widget.Sherlock.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_jcodestyle</item>
    </style>

    <style name="ActionBarTabStyle.Jcodestyle" parent="@style/Widget.Sherlock.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_jcodestyle</item>
    </style>

    <style name="DropDownNav.Jcodestyle" parent="@style/Widget.Sherlock.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/spinner_background_ab_jcodestyle</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_jcodestyle</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_jcodestyle</item>
    </style>

    <style name="ProgressBar.Jcodestyle" parent="@style/Widget.Sherlock.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_jcodestyle</item>
    </style>

    <style name="ActionButton.CloseMode.Jcodestyle" parent="@style/Widget.Sherlock.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_jcodestyle</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Jcodestyle.Widget" parent="@style/Theme.Sherlock">
        <item name="popupMenuStyle">@style/PopupMenu.Jcodestyle</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Jcodestyle</item>
    </style>
4

1 回答 1

0

请尝试在调用后移动您的代码super.onCreate(savedInstanceState)应该如下所示

super.onCreate(savedInstanceState);
setContentView(com.example.rhemamedicare.R.layout.homeactivity);    
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setIcon(android.R.color.transparent);
于 2013-10-17T14:42:50.283 回答