操作按钮进入quickActionBar GreenDroid

时间:2012-06-02 15:24:21

标签: android greendroid

我正在创建一个带有greendroid的动作栏。我设法创建了操作栏,然后快速行动。我的问题只是关于快速操作,因为我不知道如何为每个按钮快速操作插入操作。谁能帮助我? 这张照片更好地解释了我的所作所为:

http://s7.postimage.org/iavbl44mj/greendroid09.png

这是我的quickActionBar代码

private void initQuickActionBar() {
        quickActions = new QuickActionBar(this);

        quickActions.addQuickAction(new QuickAction(this, R.drawable.buscar, "Buscar"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.tags, "Tags"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));

        quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {

            @Override
            public void onQuickActionClicked(QuickActionWidget widget, int position) {



            }
        });

THKS!

1 个答案:

答案 0 :(得分:1)

您必须使用方法 onHandleActionBarItemClick

@Override
    public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
    switch (item.getItemId()) {
    case LOCATE:
          //show toast
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton LOCATE",
            Toast.LENGTH_SHORT).show();
        break;

    case REFRESH:
          //show toast
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton REFRESH",
            Toast.LENGTH_SHORT).show();
        break;

    case SHARE:
         // show quicAction and then a toas
         quickActions.show(item.getItemView());
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton SHARE",
            Toast.LENGTH_SHORT).show();
        break;
    default:
        return super.onHandleActionBarItemClick(item, position);
    }

    return true;
    }

在你的活动中你应该有类似的东西

import greendroid.app.GDActivity;
import android.os.Bundle;

public class GDIntroActivity extends GDActivity {

   private QuickActionWidget quickActions;

    /** Called when the activity is first created. */
@Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   setActionBarContentView(R.layout.main);
   initActionBar();
   initQuickActionBar();
   }

private void initQuickActionBar() {
    quickActions = new QuickActionBar(this);
    quickActions.addQuickAction(new QuickAction(this, R.drawable.facebook,
        "Facebook"));
    quickActions.addQuickAction(new QuickAction(this, R.drawable.twitter, "Twitter"));
    quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));
    quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {
        public void onQuickActionClicked(QuickActionWidget widget,
            int position) {
         Toast.makeText(GDIntroActivity.this,
         "Item " + position + " clicked", Toast.LENGTH_SHORT)
         .show();
        }
    });
    }
}

检查link 如果你想在Facebook登录午餐,你可以使用这个

Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);

但必须在您的设备或模拟器上安装Facebook应用程序才能触发它

你可以在你的QuickAction中使用它像这样

private void initQuickActionBar() {
        quickActions = new QuickActionBar(this);
        quickActions.addQuickAction(new QuickAction(this, R.drawable.facebook,
            "Facebook"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.twitter, "Twitter"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));
        quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {
            public void onQuickActionClicked(QuickActionWidget widget,
                int position) {
             switch(position){
              case facebook_position:
                   Intent intent = new Intent("android.intent.category.LAUNCHER");
                   intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
                   startActivity(intent);
                   break;
              case twitter_position:
                //do stuff

             }
            }
    });
    }