Context Action Bar Using DialogFragment

I am trying to implement a contextual action bar along with a dialog fragment. Like download widget in android.

enter image description here

I tried to set android:windowActionModeOverlayas true in the subject.

But it does not seem to work. Is there any way I can achieve this?

+5
source share
2 answers

The download window that you have in the screenshot is actually Activityusing a theme @android:style/Theme.Holo.Dialog, which makes it look like a dialog. To achieve the same look as the download window, yours Activityshould use only the same theme.

You can install this theme in your manifest like this:

<activity android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Dialog" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

, .

:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mceley.dialog.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo.Dialog" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java:

package com.mceley.dialog.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);

        findViewById(R.id.context_button).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        ExampleMode mode = new ExampleMode();
        startActionMode(mode);
    }

    public class ExampleMode implements ActionMode.Callback {

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.main_menu, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }
    }
}

main_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <Button android:id="@+id/context_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/show_context_bar" />

</LinearLayout>

main_menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/action_settings"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
</menu>

:

Dialog Example App

+4

, ActionBar DialogFragment.

Activity As.

ActionBarSherlock, R.style.Sherlock___Theme_Dialog Activity, :

enter image description hereenter image description hereenter image description here

, ActionBar Dialog DialogFragment.

0