保持常量我为多个活动定义的自定义操作栏布局

时间:2015-12-07 07:22:36

标签: android android-activity android-actionbar

对于我的应用,我通过定义ActionBarlayout来制作自定义icons。那ActionBar从两边滑落。现在,当我从sliding menu选择一个选项时,我会从当前activity导航到下一个activity,但在此activity中,我还想显示我已定义的ActionBar使用action作为之前activity的工作。请帮我 。我的代码在这里......

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dash_board);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    googleMap = mapFragment.getMap();
    mNav = new SimpleSideDrawer(this);

    mNav.setLeftBehindContentView(R.layout.activity_behind_left_simple);

    initialization();

    findViewById(R.id.acti_login_backImg).setOnClickListener(
            new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mNav.toggleLeftDrawer();
                }
            });

    mNav.setRightBehindContentView(R.layout.activity_behind_right_simple);

    findViewById(R.id.acti_dashboard_profileSlideImg).setOnClickListener(
            new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mNav.toggleRightDrawer();
                }
            });

我的事件听众

@Override
protected void onStart() {
    super.onStart();
    acti_dashboard_backToMapTxt.setOnClickListener(this);
    acti_dashboard_zoneTxt.setOnClickListener(this);
    acti_dashboard_historyTxt.setOnClickListener(this);
    acti_dashboard_settingTxt.setOnClickListener(this);
    acti_dashboard_profileTxt.setOnClickListener(this);
    acti_dashboard_newLooqiTxt.setOnClickListener(this);
    acti_dashboard_languageiTxt.setOnClickListener(this);
    acti_dashboard_unsubscribeTxt.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.acti_dashboard_backToMapTxt:
        Toast.makeText(getApplicationContext(), "MAin DashBoard Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_zoneTxt:
        Toast.makeText(getApplicationContext(), "Zone Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_historyTxt:
        Toast.makeText(getApplicationContext(), "History Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_settingTxt:
        Toast.makeText(getApplicationContext(), "Settings Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_profileTxt:
        Toast.makeText(getApplicationContext(), "Profile Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_newLooqiTxt:
        Toast.makeText(getApplicationContext(), "Add Looqi Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_languageiTxt:
        Toast.makeText(getApplicationContext(), "Language Activity",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.acti_dashboard_unsubscribeTxt:
        Toast.makeText(getApplicationContext(), "Logout Activity",
                Toast.LENGTH_SHORT).show();
        Intent logout_intent = new Intent(ActivityDashBoard.this,
                ActivityLogOut.class);
        logout_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(logout_intent);
        break;
    default:
        break;
    }
}

1 个答案:

答案 0 :(得分:0)

对于多项活动: - 您需要始终放置并实例化您的actionBar。 ActionBar是您活动的一部分。您可以为actionBar创建单个xml布局,并在include中使用activity layout xml标记。

另一部分,如果您想让actionBar成为静态,那么只需使用一项活动并为所有fragment创建slidingMenu's } options。