package com.demo.mddemo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
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.MenuItem;
import android.view.View;
import android.widget.TextView;
/**
* Created by liwen on 2016/11/23.
*/
public class MainActivity extends AppCompatActivity {
private TabLayout mTablayout;
private Toolbar mToolBar;
private ViewPager mViewPager;
public static final String[] titles = {"tab1", "tab2", "tab3", "tab4"};
private DrawerLayout mDrawLayout;
private NavigationView mNavigView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.md_activity);
initViews();
initNavigationView();
}
private void initViews() {
mTablayout = (TabLayout) findViewById(R.id.tablayout);
mToolBar = (Toolbar) findViewById(R.id.toolbar);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mDrawLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mNavigView = (NavigationView) findViewById(R.id.navigation_view);
mToolBar.setTitle("设计");
setSupportActionBar(mToolBar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawLayout, mToolBar, R.string.toggle_start, R.string.toggle_end);
mDrawLayout.addDrawerListener(toggle);
toggle.syncState();
ViewpageAdapter adapter = new ViewpageAdapter(getSupportFragmentManager(), titles);
mViewPager.setAdapter(adapter);
mTablayout.setTabMode(TabLayout.MODE_FIXED); //默认样式 其他:MODE_SCROLLABLE
mTablayout.setTabGravity(TabLayout.GRAVITY_FILL);//默认样式 其他 :GRAVITY_CENTER
mTablayout.setupWithViewPager(mViewPager);
mTablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition(), false);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
private void initNavigationView() {
TextView mHeaderTitle = (TextView) mNavigView.getHeaderView(0).findViewById(R.id.header_title);
mHeaderTitle.setText("我是头文件");
mNavigView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case R.id.menu_share:
Snackbar.make(mDrawLayout, "分享", Snackbar.LENGTH_SHORT).setAction("知道了", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}).show();
break;
case R.id.menu_search:
Snackbar.make(mDrawLayout, "搜索", Snackbar.LENGTH_SHORT).show();
break;
case R.id.menu_setting:
Snackbar.make(mDrawLayout, "设置", Snackbar.LENGTH_SHORT).show();
break;
case R.id.menu_about:
Snackbar.make(mDrawLayout, "关于", Snackbar.LENGTH_SHORT).show();
break;
}
mDrawLayout.closeDrawer(GravityCompat.START);
return true;
}
});
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android Material design设计风格
共75个文件
xml:36个
java:9个
bin:6个
需积分: 5 30 下载量 85 浏览量
2016-11-23
18:03:35
上传
评论
收藏 417KB ZIP 举报
温馨提示
DrawerLayout+CoordinatorLayout+AppBarLayout+Toolbar+TabLayout+ViewPager+NavigationView+Snackbar 实现了抽屉效果 和滑动时Toolbar自动消失等效果
资源推荐
资源详情
资源评论
收起资源包目录
MdDemo.zip (75个子文件)
MdDemo
gradlew.bat 2KB
gradlew 5KB
gradle.properties 872B
.gradle
2.10
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 20KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 25KB
taskArtifacts
fileHashes.bin 146KB
cache.properties.lock 17B
taskArtifacts.bin 66KB
fileSnapshots.bin 1.32MB
cache.properties 31B
outputFileStates.bin 20KB
app
proguard-rules.pro 662B
src
test
java
com
demo
mddemo
ExampleUnitTest.java 322B
androidTest
java
com
demo
mddemo
ApplicationTest.java 358B
main
res
menu
menu_main.xml 894B
mipmap-xxxhdpi
ic_launcher.png 10KB
drawable
mipmap-hdpi
ic_launcher.png 3KB
values
colors.xml 214B
strings.xml 168B
styles.xml 673B
dimens.xml 216B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
layout
fragment_tab4.xml 3KB
fragment_tab3.xml 3KB
md_activity.xml 2KB
activity_main.xml 711B
header_layout.xml 582B
fragment_tab1.xml 2KB
fragment_tab2.xml 3KB
values-w820dp
dimens.xml 364B
java
com
demo
mddemo
Tab2Fragment.java 568B
Tab4Fragment.java 568B
Tab1Fragment.java 905B
ViewpageAdapter.java 1KB
MainActivity.java 4KB
BaseFragment.java 168B
Tab3Fragment.java 568B
AndroidManifest.xml 674B
app.iml 11KB
.gitignore 8B
build.gradle 691B
libs
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 231B
.idea
gradle.xml 739B
runConfigurations.xml 564B
misc.xml 3KB
.name 6B
copyright
profiles_settings.xml 76B
modules.xml 349B
encodings.xml 159B
compiler.xml 686B
workspace.xml 156KB
libraries
recyclerview_v7_24_2_0.xml 779B
support_core_utils_24_2_1.xml 777B
support_compat_24_2_1.xml 931B
support_media_compat_24_2_1.xml 973B
support_fragment_24_2_1.xml 945B
support_vector_drawable_24_2_1.xml 640B
support_annotations_24_2_1.xml 495B
support_core_ui_24_2_1.xml 938B
animated_vector_drawable_24_2_1.xml 645B
support_v4_24_2_1.xml 420B
hamcrest_core_1_3.xml 526B
appcompat_v7_24_2_1.xml 761B
junit_4_12.xml 477B
design_24_2_0.xml 725B
MdDemo.iml 937B
.gitignore 105B
local.properties 428B
settings.gradle 16B
build.gradle 521B
共 75 条
- 1
资源评论
李四爷
- 粉丝: 42
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功