Created
July 1, 2018 18:06
-
-
Save root-ansh/a6db15a2dd5919ec56ff7afb762fc34c to your computer and use it in GitHub Desktop.
Default generated files for the navigation drawer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- styles.xml --> | |
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
</style> | |
<style name="AppTheme.NoActionBar"> | |
<item name="windowActionBar">false</item> | |
<item name="windowNoTitle">true</item> | |
</style> | |
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> | |
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> | |
</resources> | |
<!-- _______________________________________________________ --> | |
<!-- Styles v21.xml --> | |
<resources> | |
<style name="AppTheme.NoActionBar"> | |
<item name="windowActionBar">false</item> | |
<item name="windowNoTitle">true</item> | |
<item name="android:statusBarColor">@android:color/transparent</item> | |
</style> | |
</resources> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- activity_main.xml --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.v4.widget.DrawerLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/drawer_layout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
> | |
<include | |
layout="@layout/app_bar_main" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
<android.support.design.widget.NavigationView | |
android:id="@+id/nav_view" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_gravity="start" | |
android:fitsSystemWindows="true" | |
app:headerLayout="@layout/nav_header_main" | |
app:menu="@menu/activity_main_drawer" /> | |
</android.support.v4.widget.DrawerLayout> | |
<!-- _______________________________________________________________________________________ --> | |
<!-- appbar main.xml --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.design.widget.CoordinatorLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<android.support.design.widget.AppBarLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:theme="@style/AppTheme.AppBarOverlay"> | |
<android.support.v7.widget.Toolbar | |
android:id="@+id/toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize" | |
android:background="?attr/colorPrimary" | |
app:popupTheme="@style/AppTheme.PopupOverlay" /> | |
</android.support.design.widget.AppBarLayout> | |
<include layout="@layout/content_main" /> | |
</android.support.design.widget.CoordinatorLayout> | |
<!-- _______________________________________________________________________________________ --> | |
<!-- content_main.xml --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:layout_behavior="@string/appbar_scrolling_view_behavior" | |
tools:context=".MainActivity" | |
android:orientation="vertical" | |
tools:showIn="@layout/app_bar_main"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hello World!" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<!-- _______________________________________________________________________________________ --> | |
<!-- nav_header_main.xml --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/nav_header_height" | |
android:background="@drawable/side_nav_bar" | |
android:gravity="bottom" | |
android:orientation="vertical" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:theme="@style/ThemeOverlay.AppCompat.Dark"> | |
<ImageView | |
android:id="@+id/imageView" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:contentDescription="@string/nav_header_desc" | |
android:paddingTop="@dimen/nav_header_vertical_spacing" | |
app:srcCompat="@mipmap/ic_launcher_round" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:paddingTop="@dimen/nav_header_vertical_spacing" | |
android:text="@string/nav_header_title" | |
android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/nav_header_subtitle" /> | |
</LinearLayout> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ansh.win.work.a0testingdefaultgeneratedcode2; | |
import android.os.Bundle; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.design.widget.Snackbar; | |
import android.view.View; | |
import android.support.design.widget.NavigationView; | |
import android.support.v4.view.GravityCompat; | |
import android.support.v4.widget.DrawerLayout; | |
import android.support.v7.app.ActionBarDrawerToggle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
public class MainActivity extends AppCompatActivity | |
implements NavigationView.OnNavigationItemSelectedListener { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar 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, "Replace with your own action", Snackbar.LENGTH_LONG) | |
.setAction("Action", null).show(); | |
} | |
}); | |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | |
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( | |
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); | |
drawer.addDrawerListener(toggle); | |
toggle.syncState(); | |
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); | |
navigationView.setNavigationItemSelectedListener(this); | |
} | |
@Override | |
public void onBackPressed() { | |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | |
if (drawer.isDrawerOpen(GravityCompat.START)) { | |
drawer.closeDrawer(GravityCompat.START); | |
} else { | |
super.onBackPressed(); | |
} | |
} | |
@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_camera) { | |
// Handle the camera action | |
} else if (id == R.id.nav_gallery) { | |
} else if (id == R.id.nav_slideshow) { | |
} else if (id == R.id.nav_manage) { | |
} else if (id == R.id.nav_share) { | |
} else if (id == R.id.nav_send) { | |
} | |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | |
drawer.closeDrawer(GravityCompat.START); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment