两个动作条(下和上)在同一时间? [英] Two action bars (Bottom and Up) at the same time?

查看:125
本文介绍了两个动作条(下和上)在同一时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要进行两个动作吧,我现在用actionBarSherlock的方式。所以,我需要的恰恰是把对正常操作栏了欢迎屏幕切换,并添加两个正常的动作条​​操作选项。类似的什么,我需要的是Gmail和地图喜欢这里:的http://cdn.androidcommunity.com/wp-content/uploads/2012/03/Screenshot_2012-03-28-12-58-16.png (他们没有让我张贴图片的声誉很低,看到该链接,请)

I have need to make two action bars , I am using actionBarSherlock by the way . So what I need exactly is to put a "Welcome screen" toggle on the normal action bar up , and add two normal ActionBar Action options . Similar to what I need are Gmail and Maps like here : http://cdn.androidcommunity.com/wp-content/uploads/2012/03/Screenshot_2012-03-28-12-58-16.png (They didn't allow me to post an image for reputation is low , see the link please)

该地图应用程序具有上,下行动起来吧,正是我需要的,因为一旦我达到的地步,我可以添加第二个动作条我知道从哪里开始...

This Maps app has an upper and bottom action bar , exactly what I need , because once I reach the point where I can add the second actionbar I know where to start ...

我寻觅一个星期左右关于这个话题,我也发现了一些类似的问题,但是,但是我明白非的答案;答案是哪些,我不是(所有)熟悉,我不明白的事情的自定义视图,但是是我试图做一个自定义视图无论从任何我认为是对的,我有crrassshheesss我没找不到了......如果它是如何使用的这两个动作条,你可以PLZ告诉我,例如,该地图应用程序的任何解决方案? (我不希望浏览像地图和Gmail,但只有两个其他动作)

I have searched for about a week about this topic and I have found a few similar questions , but however I have understood non of the answers ; the answers were about a custom view which I am not (at all) familiar with and I can't understand a thing , but yes I tried to make a "custom view" from whatever I thought is right and I got crrassshheesss which I didn't find any solution for ... If you may plz show me as an example this Maps app how is it using those two action bars ?? (I don't want to navigate like in maps and gmail , but only the two actionbars)

下面是我的一些code:

Here is some of my code :

//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);
    }

我的清单:

<?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>

和我的菜单我打算把它们放在我的行动吧...

And my menus which I intend to put them in my action bars ...

菜单\ activity_main.xml

menu\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>

菜单\ upper_navbar.xml(如果已经将其命名为upper_actionbar,但它只是一个思想的错误,它的名字毕竟,:/ PLZ继续)

menu\upper_navbar.xml (Should have named it upper_actionbar but its just a thinking mistake , its a name afterall , :/ plz proceed )

<?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>

如果你需要的信息了,请告诉我,我会告诉,它为我和其他人毕竟!

If you need anymore info please tell me , I will tell , its for me and everyone else afterall !

编辑! 我发现一个更近的例子我的问题时,无线网络设置(的http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png)它使用正常的动作条​​和正常分裂的开关动作条了!正是我需要的!

EDIT !!! : I found a much near example to my question , the wifi settings (http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png) It uses a switch in the normal actionbar and a normal split actionbar down ! Exactly what I need !

编辑2 !!!! :下面是使用基于在AOSP定制ROM我的Galaxy Nexus的截图,这正是我需要的,意思是:

EDIT 2 !!!! : Here is a screenshot from my Galaxy nexus using a custom ROM based over aosp , This is exactly what I need and mean :

设置 - 无线上网:<一href="https://lh4.googleusercontent.com/-aeL_sHjIcQQ/UPVptGQiuqI/AAAAAAAAAGE/UGc-CuLP4Qw/s512/Screenshot_2013-01-15-16-36-32.png" rel="nofollow">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

Settings-Bluetooth: lh3*googleusercontent.com/-4j6ca1Nm1VI/UPVqAiDn_PI/AAAAAAAAAGM/LLB2ILWVjQY/s512/Screenshot_2013-01-15-16-38-14.png

编辑3 !!! :在我的蓝牙和WiFi调查大进步,正如我所说的,问,他们是真正的为其他动作!看看我的设置 - 蓝牙有:

EDIT 3 !!! : Big progress in my investigation in the Bluetooth and Wifi , and as I said and asked , they were true actionbars ! see what I got in Settings-Bluetooth:

BluetoothSettings.class / onCreateOptionsMenu:

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);
    }

这些可选项清楚地显示在splitActionBarDown的确切属性起来......

These can be options are clearly shown in the splitActionBarDown with the exact properties up ...

现在:

BluetoothSettings.class /加preferencesForActivity:

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);
    }

注意到这个类是不扩展活动,它扩展DEVICELIST preferenceFragment ...

现在我们知道了有可能有两个其他动作(分割和正常)的同时,我们需要一种方法来简化,也许是一个类或库??

Now that we know it's possible to have two actionbars(split and normal) in the same time , we need a way to simplify that , maybe by a class or library ??

推荐答案

这是一个的拆分操作栏。它可用于具有400dp℃的屏幕宽度手持机装置; 要启用拆分操作栏,只需添加 uiOptions =splitActionBarWhenNarrow您或清单元素。

That is a split action bar. It is available for handset devices with a screen width of 400dp< To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your or manifest element.

编辑: 第二个图像的确是一个不拆分操作栏。这些都与buttonBarButtonStyle属性只按钮。看看<一href="http://stackoverflow.com/questions/8855791/how-to-create-standard-borderless-buttons-like-in-the-design-guidline-mentioned">this在这里。

The second image is indeed not a split action bar. These are just buttons with the buttonBarButtonStyle attribute. Look into this here.

编辑:

splitActionBarWhenNarrow 一直的德precated

这篇关于两个动作条(下和上)在同一时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆