How to get the action bar for dialog style actions with appcompat-v7 22.1?

Some prerequisites: I am adding tablet support for a game that has previously been available on phones for a long time. Some of these actions constitute a "wizard" in which the user chooses the type of game, some parameters and the opponent before starting the game. For a tablet version using a theme that inherits Theme.AppCompat.DialogWhenLarge

, these steps looked like a good, simple solution. This works great when using appomppat-v7 version 22.0.0.

In appcompat-v7 version 22.1, in all these actions, DialogWhenLarge suddenly getSupportActionBar()

started returning null

to tablets. I relied on the action bar for back navigation and more importantly for search and other buttons.

How can you create an action bar for these actions on tablets? Do I need to implement my own dashboard?

I tried to call requestWindowFeature(Window.FEATURE_ACTION_BAR)

mine onCreate

(before calling super), but that has no effect. I've tried subclassing from AppCompatActivity

instead ActionBarActivity

, but it didn't help either (with and without requestWindowFeature).

I read the Chris Banes blog post about this new version of the library, as well as the "Jan post " on the Android developers blog; I haven't seen anything to say that action bars will no longer be available.

+3


source to share


1 answer


I had the same problem. The only way I could find was to replace action bars with toolbars.

// Replace the action bar with a toolbar
Toolbar toolbar = (Toolbar)findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);

      

My toolbar layout:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/DefaultActionBarTheme"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

      



included in my activity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/detail_root"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

    <include android:id="@+id/tool_bar" layout="@layout/tool_bar" />

    <ListView
        android:id="@+id/detail_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="always" />
</LinearLayout>

      

DefaultActionBarTheme (in styles.xml):

<!-- Action bar theme -->
<style name="DefaultActionBarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorControlNormal">#1d7caf</item>
</style>

      

+4


source







All Articles