Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid support-v7-appcompat issue with 4.0 & above
    primarykey
    data
    text
    <p>I am backporting my Android application to support older devices (2.3.3+). Previously, it was 4.0+.</p> <p>I am using ActionBar and doing custom styling on it in code in the base class. After conversion to Support ActionBar, the styling code is:</p> <pre><code>public static void styleActionBar(final ActionBarActivity activity) { /* Setup the actionbar as required */ final ActionBar actionBar = activity.getSupportActionBar(); if (actionBar != null) { actionBar.setBackgroundDrawable(new ColorDrawable(0xfffffff)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.customview_actionbar); .... } } </code></pre> <p>After this change, all things work perfectly on 2.3.3. But, for 4.0+, it crashes at the line</p> <pre><code> actionBar.setBackgroundDrawable(new ColorDrawable(0xfffffff)); </code></pre> <p>Also, if I comment this line out, I can see that it crashes at <code>actionBar.setCustomView</code> also.</p> <p>Stack trace on 4.2:</p> <pre><code>.... Caused by: java.lang.NullPointerException at android.support.v7.app.ActionBarImplICS.setBackgroundDrawable(ActionBarImplICS.java:176) at com.mycompany.myproj.ProjBaseActivity.styleActionBar(ProjBaseActivity.java:68) at com.mycompany.myproj.ProjBaseActivity.onCreate(ProjBaseActivity.java:32) at com.mycompany.myproj.TextSearchActivity.onCreate(TextSearchActivity.java:60) at android.app.Activity.performCreate(Activity.java:5008) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139) </code></pre> <p>It works perfectly in 2.3.3 &amp; it looks to me like an issue in support-v7-appcompat.</p> <p>Any clues / help on overcoming or working around ? Thanks in advance.</p> <p>Edit 1: <code>values-v14/styles.xml</code> content:</p> <pre><code>&lt;resources&gt; &lt;style name="MyTheme" parent="@style/Theme.AppCompat.Light"&gt; &lt;item name="android:actionBarStyle"&gt;@style/MyTheme.ActionBarStyle&lt;/item&gt; &lt;/style&gt; &lt;style name="MyTheme.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar"&gt; &lt;item name="android:titleTextStyle"&gt;@style/MyTheme.ActionBar.TitleTextStyle&lt;/item&gt; &lt;/style&gt; &lt;style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"&gt; &lt;item name="android:textColor"&gt;@color/proj_theme_color&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload