2015-02-02 2 views
1

Я попытался это:Toolbar - findViewById является нулевым

Toolbar - findViewbyID returning null.

Я получаю нулевой указатель на «findViewById» даже тогда.

themes.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

<style name="Theme.Customtheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
    <item name="actionBarItemBackground">@drawable/selectable_background_customtheme</item> 
    <item name="popupMenuStyle">@style/PopupMenu.Customtheme</item> 
    <item name="dropDownListViewStyle">@style/DropDownListView.Customtheme</item> 
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Customtheme</item> 
    <item name="actionDropDownStyle">@style/DropDownNav.Customtheme</item> 
    <item name="actionBarStyle">@style/ActionBar.Solid.Customtheme</item> 
    <item name="actionModeBackground">@drawable/cab_background_top_customtheme</item> 
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_customtheme</item> 
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Customtheme</item> 
      <!-- Light.DarkActionBar specific --> 
    <item name="actionBarWidgetTheme">@style/Theme.Customtheme.Widget</item> 
    <item name="android:buttonStyle">@style/Theme.CustomTheme.Widget.Button</item> 
    <item name="android:textViewStyle">@style/Theme.CustomeTheme.Widget.TextViewStyle</item> 
    <item name="android:windowBackground">@drawable/appbackground</item> 
    <item name="actionMenuTextColor">@color/orange</item> 
    <item name="actionBarTabTextStyle">@style/TabStyle</item> 
    <item name="windowActionBar">false</item> 
</style> 

<style name="TabStyle" parent="@style/Widget.AppCompat.Light.ActionBar.TabText.Inverse"> 
    <item name="android:textColor">@color/blue</item> 
    <item name="android:textStyle">normal</item> 
</style> 

<style name="ActionBar.Solid.Customtheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="background">@drawable/ab_solid_customtheme</item> 
    <item name="backgroundStacked">@drawable/ab_stacked_solid_customtheme</item> 
    <item name="backgroundSplit">@drawable/ab_bottom_solid_customtheme</item> 
    <item name="progressBarStyle">@style/ProgressBar.Customtheme</item> 
    <item name="titleTextStyle">@style/Theme.CustomTheme.WindowTitleTextStyle</item> 
    <item name="android:icon">@drawable/movie</item> 
</style> 

<style name="Theme.CustomTheme.WindowTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="android:paddingLeft">10dip</item> 
    <item name="android:textColor">@color/orange</item> 
</style> 

<style name="ActionBar.Transparent.Customtheme" parent="@style/Widget.AppCompat.ActionBar"> 
    <item name="background">@drawable/ab_transparent_customtheme</item> 
    <item name="progressBarStyle">@style/ProgressBar.Customtheme</item> 
</style> 

<style name="PopupMenu.Customtheme" parent="@style/Widget.AppCompat.PopupMenu"> 
    <item name="android:popupBackground">@color/white</item> 
    <item name="android:actionMenuTextColor">@color/blue</item> 
</style> 

<style name="DropDownListView.Customtheme" parent="@style/Widget.AppCompat.ListView.DropDown"> 
    <item name="android:listSelector">@drawable/selectable_background_customtheme</item> 
</style> 

<style name="ActionBarTabStyle.Customtheme" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
    <item name="background">@drawable/tab_indicator_ab_customtheme</item> 
</style> 

<style name="DropDownNav.Customtheme" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar"> 
    <item name="background">@drawable/spinner_background_ab_customtheme</item> 
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_customtheme</item> 
    <item name="android:dropDownSelector">@drawable/selectable_background_customtheme</item> 
</style> 

<style name="ProgressBar.Customtheme" parent="@style/Widget.AppCompat.ProgressBar.Horizontal"> 
    <item name="android:progressDrawable">@drawable/progress_horizontal_customtheme</item> 
</style> 

<style name="ActionButton.CloseMode.Customtheme" parent="@style/Widget.AppCompat.ActionButton.CloseMode"> 
    <item name="background">@drawable/btn_cab_done_customtheme</item> 
</style> 

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

V14-themes.xml:

<resources> 

<style name="Theme.Customtheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 

    <item name="android:actionBarItemBackground">@drawable/selectable_background_customtheme</item> 
    <item name="android:popupMenuStyle">@style/PopupMenu.Customtheme</item> 
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Customtheme</item> 
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Customtheme</item> 
    <item name="android:actionDropDownStyle">@style/DropDownNav.Customtheme</item> 
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Customtheme</item> 
    <item name="android:actionModeBackground">@drawable/cab_background_top_customtheme</item> 
    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_customtheme</item> 
    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Customtheme</item> 
    <!-- Light.DarkActionBar specific --> 
    <item name="android:actionBarWidgetTheme">@style/Theme.Customtheme.Widget</item> 
    <item name="android:buttonStyle">@style/Theme.CustomTheme.Widget.Button</item> 
    <item name="android:textViewStyle">@style/Theme.CustomeTheme.Widget.TextViewStyle</item> 
    <item name="android:windowBackground">@drawable/appbackground</item> 
    <item name="android:actionMenuTextColor">@color/orange</item> 
    <item name="@android:attr/actionBarTabTextStyle">@style/TabStyle</item> 
    <item name="windowActionBar">false</item> 


</style> 

<style name="ActionBar.Solid.Customtheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background">@drawable/ab_solid_customtheme</item> 
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_customtheme</item> 
    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_customtheme</item> 
    <item name="android:progressBarStyle">@style/ProgressBar.Customtheme</item> 
    <item name="android:titleTextStyle">@style/Theme.CustomTheme.WindowTitleTextStyle</item> 
    <item name="android:icon">@drawable/movie</item> 
</style> 

<style name="ActionBar.Transparent.Customtheme" parent="@style/Widget.AppCompat.ActionBar"> 
    <item name="android:background">@drawable/ab_transparent_customtheme</item> 
    <item name="android:progressBarStyle">@style/ProgressBar.Customtheme</item> 
</style> 

<style name="Theme.CustomTheme.WindowTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="android:paddingLeft">10dip</item> 
    <item name="android:textColor">@color/orange</item> 
</style> 

<!-- this style is only referenced in a Light.DarkActionBar based theme --> 
<style name="Theme.Customtheme.Widget" parent="@style/Theme.AppCompat"> 
    <item name="android:popupMenuStyle">@style/PopupMenu.Customtheme</item> 
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Customtheme</item> 
    <item name="windowActionBar">false</item> 
</style> 

V21-themes.xml:

<?xml version="1.0" encoding="utf-8"?> 

<item name="android:windowContentTransitions">true</item> 
    <item name="android:windowAllowEnterTransitionOverlap">true</item> 
    <item name="android:windowAllowReturnTransitionOverlap">true</item> 
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> 
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
    <item name="android:windowActionModeOverlay">true</item> 
    <item name="android:actionModeStyle">@style/MyTheme.ActionMode</item> 
    <item name="windowActionBar">false</item> 
</style> 

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@android:color/white</item> 
</style> 

<style name="MyTheme.ActionMode" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:colorPrimary">@color/blue</item> 
    <item name="android:colorPrimaryDark">@color/blue</item> 
    <item name="actionModeBackground">@color/blue</item> 
    <item name="android:colorBackground">@color/blue</item> 
</style> 

styles.xml:

<?xml version="1.0" encoding="utf-8"?> 

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:windowContentTransitions">true</item> 
    <item name="android:windowAllowEnterTransitionOverlap">true</item> 
    <item name="android:windowAllowReturnTransitionOverlap">true</item> 
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> 
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
    <item name="android:windowActionModeOverlay">true</item> 
    <item name="android:actionModeStyle">@style/MyTheme.ActionMode</item> 
    <item name="windowActionBar">false</item> 
</style> 

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@android:color/white</item> 
</style> 

<style name="MyTheme.ActionMode" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="actionModeBackground">@color/blue</item> 
</style> 

Я не уверен, что это не так!

ответ

0

Чтобы включить панель инструментов, вы должны отключить панель действий по умолчанию в своем стиле, наследуя родительскую тему без панели действий.

Нечто подобное

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/myPrimaryColor</item> 
     <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item> 
     <item name="colorAccent">@color/myAccentColor</item> 
     <item name="android:textColorPrimary">@color/myAccentColor</item> 
     <item name="android:textColor">@color/myAccentColor</item> 
     <item name="android:textColorSecondary">@color/myAccentColor</item> 
     <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
     <item name="android:windowBackground">@color/myWindowBackground</item> 
    </style> 

После этого вы можете найти панель инструментов с вашего ID ресурса.

+0

Я уже отключил его включением false stallianz

0

В дополнении к отключив бар Действия по умолчанию, перед вызовом findViewById(), окна своей деятельности должны первого быть созданы с помощью вызова setContentView(), а не в обратном порядке!

Смежные вопросы