我正在创建一个带有绿色机器人的动作栏。我设法创建了操作栏,然后快速操作。我的问题只是关于快速操作,因为我不知道如何为每个按钮快速操作插入操作。谁能帮我?这张图片更好地解释了我的工作:
http://s7.postimage.org/iavbl44mj/greendroid09.png
这是我的快速操作栏代码
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) {
}
});
谢谢!
您必须使用 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();
}
});
}
}
检查此链接如果你想午餐Facebook登录,你可以使用这个
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
但是必须在您的设备或模拟器上安装Facebook应用程序才能触发它
您可以像这样在快速操作中使用它
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
}
}
});
}