从父类保存的实例状态

时间:2016-06-14 23:06:29

标签: java android xml

我正在开发一款Android应用。我制作了一个BottomBar设计,我必须把它作为一个单独的类来在所有活动中使用它。问题是,当我从调用条形图的活动中调用bottomBar.attach()时,我无法获取savedInstanceState(我得到'无法解析符号'错误)。这是我的代码:

public class bottom_bar extends AppCompatActivity {
private BottomBar bottomBar;
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
}

private CoordinatorLayout coordinatorLayout;

public void start() {
    coordinatorLayout = (CoordinatorLayout) findViewById(android.R.id.content);
    bottomBar = BottomBar.attach(this, savedInstanceState);
    bottomBar.setItemsFromMenu(R.menu.three_buttons_menu, new OnMenuTabSelectedListener() {
        @Override
        // Qué hacer cuando se aprieta cada botón de la barra.
        public void onMenuItemSelected(int itemId) {
            switch (itemId) {
                case R.id.recent_item:
                    break;
                case R.id.favorite_item:
                    break;
                case R.id.location_item:
                    break;
            }
        }

        // Qué hacer cuando se aprieta de nuevo cada botón de la barra.
        public void onMenuTabReSelected(int itemId) {
            switch (itemId) {
                case R.id.recent_item:
                    break;
                case R.id.favorite_item:
                    break;
                case R.id.location_item:
                    break;
            }
        }
    });
    bottomBar.setActiveTabColor("#C2185B");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // Necessary to restore the BottomBar's state, otherwise we would
    // lose the current tab on orientation change.
    bottomBar.onSaveInstanceState(outState);
}

}

0 个答案:

没有答案