我一直在使用活動工具處理此導航器抽屜。我在我的項目中有幾個活動,我想使用導航抽屜進行切換。 到目前爲止,我已經實現了這個在導航抽屜中實現活動而不是片段
創建導航抽屜,寫一些活動代碼。
在所有活動中顯示相同的導航器抽屜。
開始應用程序啓動時的默認活動。
但現在我的問題是,當我第一次打開我的應用程序,它加載我想要的活動,我可以看到這個導航抽屜。當我切換活動並按下後退按鈕時,我正在使用導航抽屜獲取此空白活動。我知道它的一些初學者水平問題。但是,如果有人可以建議編輯請請。這是我的代碼。
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
NavigationView navigationView = null;
Toolbar toolbar = null;
DrawerLayout drawer;
FrameLayout frameLayout;
private static boolean isLaunch = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout) findViewById(R.id.contant_frame);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (isLaunch) {
isLaunch = false;
startActivity(new Intent (this,MyAct.class));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_manage) {
startActivity(new Intent(this,About.class));
} else if (id == R.id.nav_share) {
startActivity(new Intent(this,About.class));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
我已經此相同的應用程序中簡單列表視圖類型的資產淨值抽屜工作完美。但現在我試圖實現花式材料設計。
isLaunch是什麼? – brandall