是否可以改变扩展抽屉的样式并在活动中使用它?

时间:2017-08-03 13:52:27

标签: android android-layout android-menu android-drawer

是否可以更改扩展抽屉的样式并在活动中使用它?如果有,怎么样?我试图使用这个抽屉,使其在StoreActivity中透明

如果你好奇,这是我的代码。 HomeNavigation.java,抽屉代码

public class HomeNavigation extends AppCompatActivity {
    public DrawerLayout mDrawerLayout;
    public ActionBarDrawerToggle mToggle;
    public Toolbar mToolbar;
    public NavigationView mNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer_navigation);

        mToolbar = (Toolbar) findViewById(R.id.navigation_actionbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setTitle("Welcome Back!");

        mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.addDrawerListener(mToggle);
        mToggle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        /**ON NAVIGATION ITEM SELECTED*/
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // enabling drawer toggle by clicking on the app icon.
        if (mToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

I类尝试在StoreActivity.java中使用它

public class StoreActivity extends HomeNavigation {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.activity_drawer_navigation_transparent, null, false);
        mDrawerLayout.addView(contentView, 0);
        getSupportActionBar().setTitle("");
        mNavigationView.getMenu().getItem(1).setChecked(true);


    }
}

0 个答案:

没有答案