两个动作栏(Bottom和Up)同时出现?

Sea*_*ays 9 android android-custom-view actionbarsherlock android-actionbar

我需要制作两个动作栏,顺便说一句,我正在使用actionBarSherlock.所以我需要的是在正常操作栏上打开"欢迎屏幕",并添加两个正常的ActionBar Action选项.类似于我需要的Gmail和地图,如:http://cdn.androidcommunity.com/wp-content/uploads/2012/03/Screenshot_2012-03-28-12-58-16.png(他们没有允许我发布信誉低的图片,请看链接

这个地图应用程序有一个上下操作栏,正是我需要的,因为一旦我到达可以添加第二个操作栏的位置,我知道从哪里开始......

我已经搜索了大约一个星期关于这个主题的内容,我发现了一些类似的问题,但是我已经理解了没有答案; 答案是关于一个我不熟悉的自定义视图,我无法理解一件事,但是我试图从我认为正确的事情中做出"自定义视图",我得到了一些我没有做过的事情.找不到任何解决方案......如果你可以通过PLZ向我展示这个地图应用程序如何使用这两个动作栏?(我不想在地图和gmail中导航,但只有两个动作栏)

这是我的一些代码:

//Part of my MainActivity.class
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        MenuInflater inf = getSupportMenuInflater();
        inf.inflate(R.menu.upper_navbar, menu);

        final String name = "welcome";
        final SharedPreferences pref = getSharedPreferences(name, 0);
        final Editor edit = pref.edit();
        boolean oldState = pref.getBoolean("w", true);
        ToggleButton tog = (ToggleButton) menu.findItem(R.id.welcome_screen).getActionView();
        if(oldState){
            tog.setChecked(true);

        }else{
            tog.setChecked(false);
        }

        tog.setOnCheckedChangeListener(new OnCheckedChangeListener() {



            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    edit.putBoolean("w", true);
                    edit.apply();
                }else{
                    edit.putBoolean("w", false);
                    edit.apply();
                }


            }
        });
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
    }
Run Code Online (Sandbox Code Playgroud)

我的清单:

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:name="android.app.Application"
        android:icon="@drawable/ic_launcher"
        android:uiOptions="splitActionBarWhenNarrow"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="seaskyways.editpad.MainActivity"
            android:label="MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.editpad.Splash"
            android:theme="@style/Theme.Sherlock.Dialog.NoActionBar"


            android:label="Splash" >
            <intent-filter>
                <action android:name="android.intent.action.SPLASH" />

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

</manifest>
Run Code Online (Sandbox Code Playgroud)

我的菜单我打算将它们放在我的动作栏中......

菜单\ activity_main.xml中

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


    <item android:id="@+id/bottom_copy"  android:title="Copy" android:orderInCategory="3" android:showAsAction="ifRoom|withText" />
    <item android:id="@+id/bottom_paste" android:title="Paste" android:orderInCategory="2" android:showAsAction="ifRoom|withText" />

</menu>
Run Code Online (Sandbox Code Playgroud)

menu\upper_navbar.xml(应该将其命名为upper_actionbar但它只是一个思维错误,它的名字毕竟是://plz继续)

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

     <item
        android:id="@+id/welcome_screen"
        android:orderInCategory="1"
        android:showAsAction="ifRoom|withText"
        android:title="Welcome Screen"
        android:actionLayout="@layout/toggle"

        />

</menu>
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请告诉我,我会告诉我,它对我和其他所有人来说!

编辑!!! :我发现了一个很接近我的问题的例子,wifi设置( http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png)它使用正常操作栏中的开关和正常的拆分操作栏!正是我需要的!

编辑2 !!!! :这是我使用基于aosp的自定义ROM的Galaxy nexus截图,这正是我需要的意思:

设置-Wifi:https://lh4.googleusercontent.com/-aeL_sHjIcQQ/UPVptGQiuqI/AAAAAAAAAGE/UGc-CuLP4Qw/s512/Screenshot_2013-01-15-16-36-32.png

设置 - 蓝牙:lh3*googleusercontent.com/-4j6ca1Nm1VI/UPVqAiDn_PI/AAAAAAAAAGM/LLB2ILWVjQY/s512/Screenshot_2013-01-15-16-38-14.png

编辑3 !!! :我在蓝牙和Wifi调查方面取得了很大进展,正如我所说的那样,他们是真正的动作栏!看看我在设置 - 蓝牙中得到了什么:

BluetoothSettings.class/onCreateOptionsMenu:

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        if (mLocalAdapter == null) return;
        boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
        boolean isDiscovering = mLocalAdapter.isDiscovering();
        int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
            R.string.bluetooth_search_for_devices;
        menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
                .setEnabled(bluetoothIsEnabled && !isDiscovering)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device)
                .setEnabled(bluetoothIsEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(Menu.NONE, MENU_ID_VISIBILITY_TIMEOUT, 0, R.string.bluetooth_visibility_timeout)
                .setEnabled(bluetoothIsEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        super.onCreateOptionsMenu(menu, inflater);
    }
Run Code Online (Sandbox Code Playgroud)

这些可以选项清楚地显示在splitActionBarDown中,具有确切的属性...

现在:

BluetoothSettings.class/addPreferencesForActivity:

@Override
    void addPreferencesForActivity() {
        addPreferencesFromResource(R.xml.bluetooth_settings);

        Activity activity = getActivity();

        Switch actionBarSwitch = new Switch(activity);

        if (activity instanceof PreferenceActivity) {
            PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
            if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
                final int padding = activity.getResources().getDimensionPixelSize(
                        R.dimen.action_bar_switch_padding);
                actionBarSwitch.setPadding(0, 0, padding, 0);
                activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                        ActionBar.DISPLAY_SHOW_CUSTOM);
                activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        Gravity.CENTER_VERTICAL | Gravity.END));
            }
        }

        mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);

        setHasOptionsMenu(true);
    }
Run Code Online (Sandbox Code Playgroud)

注意到这个类没有扩展Activity,它extends DeviceListPreferenceFragment......

现在我们知道可以在同一时间内有两个动作栏(分割和普通),我们需要一种方法来简化它,可能是通过类或库?

Ahm*_*mad 5

这是一个分裂动作栏.它适用于屏幕宽度为400dp的手机设备<要启用分割操作栏,只需添加uiOptions="splitActionBarWhenNarrow"到您的或清单元素即可.

编辑:第二张图片确实不是分割操作栏.这些只是buttonBarButtonStyle属性的按钮.看看这个在这里.

编辑:

splitActionBarWhenNarrow已被弃用.

  • @Seaskyways:实际上,我怀疑Ahmad确实读过这个问题,因为他有正确的答案. (3认同)