我正在使用Hitomis circle menu library,但不知道如何单击特定的子菜单才能打开特定的活动?
我认为Hitomis库中没有类似的功能,但请告知是否有任何方法可以做到。
这是Java代码
public class MainActivity extends AppCompatActivity {
private CircleMenu circleMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circleMenu = (CircleMenu) findViewById(R.id.circle_menu);
circleMenu.setMainMenu(Color.parseColor("#CDCDCD"), R.mipmap.menuop, R.mipmap.menucl)
.addSubMenu(Color.parseColor("#258CFF"), R.drawable.chrome)
.addSubMenu(Color.parseColor("#30A400"), R.drawable.drive)
.addSubMenu(Color.parseColor("#FF4B32"), R.drawable.googlesearch)
.addSubMenu(Color.parseColor("#8A39FF"), R.drawablegmail)
.addSubMenu(Color.parseColor("#FF6A00"), R.drawable.youtube)
.setOnMenuSelectedListener(new OnMenuSelectedListener() {
@Override
public void onMenuSelected(int index) {}
}).setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {
@Override
public void onMenuOpened() { }
@Override
public void onMenuClosed() {}
});
}
答案 0 :(得分:0)
菜单选择的侦听器返回菜单的索引,例如
如果您单击第一个子菜单项addSubMenu(Color.parseColor("#258CFF"), R.drawable.chrome)
它返回index = 0,
现在,如果您想在特定的子菜单上打开活动,则可以像下面这样
setOnMenuSelectedListener(new OnMenuSelectedListener() {
@Override
public void onMenuSelected(int index) {
switch(index){
case 0: startActivity(new Intent(this,FirstActivity.class));break;
case 1: startActivity(new Intent(this,SecondActivity.class));break;
}
}
答案 1 :(得分:0)
您也可以使用if
:
.setOnMenuSelectedListener(new OnMenuSelectedListener() {
@Override
public void onMenuSelected(int i) {
if (i==0){
Intent intent = new Intent(MainActivity.this,FirstActivity.class);
startActivity(intent);
}
if (i==1){
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
}
}
});