<resources> <string name="app_name">头条</string> <string name="openDrawer">今日头条</string>\ <string name="closeDrawer">用户目录</string> </resources> /****/
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/splash"/> </LinearLayout> /**splash
<?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" android:id="@+id/drawerLayout" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--标签布局--> <android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabGravity="center" app:tabTextColor="@color/colorPrimary" app:tabIndicatorColor="@android:color/transparent" app:tabSelectedTextColor="@color/colorAccent" app:tabMode="scrollable"> </android.support.design.widget.TabLayout> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager> </LinearLayout> <!-- 菜单栏选项--> <ListView android:id="@+id/leftDrawer" android:layout_width="200dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/colorPrimary"> </ListView> </android.support.v4.widget.DrawerLayout> /**main_Activity
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.daytwo"> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".HomeActivity"/> </application> </manifest> /***manifo
package com.example.daytwo.fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class Fragment1 extends Fragment { private static final String PAGE_TITLE = "PAGE_TITLE"; private String title; public static Fragment1 newInstance(String title){ Bundle bundle = new Bundle(); bundle.putString(PAGE_TITLE,title); Fragment1 fragment1 = new Fragment1(); fragment1.setArguments(bundle); return fragment1; } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //当Fragemnt一旦被创建,我就可以接受对方传递过来的值 title = getArguments().getString(PAGE_TITLE); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { TextView textView = new TextView(getActivity()); textView.setText(title); textView.setTextSize(50); return textView; } } //fragment1
package com.example.daytwo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; /** * Created by hp on 2017/8/31. */ public class BaseActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //隐藏标题栏 //getSupportActionBar().hide(); //标题栏 ActionBar actionBar = getSupportActionBar(); //显示箭头 actionBar.setDisplayHomeAsUpEnabled(true); } }
package com.example.daytwo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import com.example.daytwo.fragment.Fragment1; import java.util.ArrayList; import java.util.List; public class HomeActivity extends BaseActivity implements AdapterView.OnItemClickListener { private DrawerLayout drawerLayout; private ListView leftDrawer; private List<String> list = new ArrayList<String>(); private ArrayAdapter<String> adapter; private ActionBarDrawerToggle toggle; private final String[] mTitles = new String[]{"推荐","热点","北京","科技","军事","视频","社会"}; private ViewPager vp; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initData(); initView(); } /** * 初始化数据 */ private void initData() { for (int i = 0; i < 5; ++i) { list.add("泡妞0" + i); } } /** * 初始化View */ private void initView() { drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); leftDrawer = (ListView) findViewById(R.id.leftDrawer); //初始化ActionBar //参数1:上下文 //参数2:抽屉 //参数3:打开抽屉的描述 //参数4:关闭抽屉的描述 toggle = new ActionBarDrawerToggle(this,drawerLayout, R.string.openDrawer,R.string.closeDrawer); //设置状态同步 toggle.syncState(); //设置抽屉打开关闭监听 drawerLayout.addDrawerListener(toggle); //设置适配器 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); leftDrawer.setAdapter(adapter); leftDrawer.setOnItemClickListener(this); //找到标签布局控件 TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); for (String str : mTitles) { //更具标签数生成标签 tabLayout.addTab(tabLayout.newTab().setText(str)); } //TabLayout关联ViewPager vp = (ViewPager) findViewById(R.id.vp); vp.setAdapter(new MyFragmentAdapter(getSupportFragmentManager())); //让TabLayout发生关联 tabLayout.setupWithViewPager(vp); } //重写该方法,监听actionbar 条目监听(箭头、三个横线) @Override public boolean onOptionsItemSelected(MenuItem item) { //如果抽屉打开,点击按钮,就会关闭,反之亦然 return toggle.onOptionsItemSelected(item) | super.onOptionsItemSelected(item); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //关闭抽屉 drawerLayout.closeDrawer(leftDrawer); } class MyFragmentAdapter extends FragmentPagerAdapter{ public MyFragmentAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return Fragment1.newInstance(mTitles[position]); } @Override public int getCount() { return mTitles.length; } //重写该方法,显示标签字体 bug @Override public CharSequence getPageTitle(int position) { return mTitles[position]; } } } //**H
package com.example.daytwo; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.RelativeLayout; public class MainActivity extends BaseActivity { private RelativeLayout rl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); //隐藏action getSupportActionBar().hide(); //动画结束,跳转9 Intent intent = new Intent(MainActivity.this, HomeActivity.class); startActivity(intent); /* rl = (RelativeLayout) findViewById(R.id.rl); playAnim(rl);*/ } /** * 播放动画 * @param view */ private void playAnim(View view) { AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); alphaAnimation.setDuration(2000); alphaAnimation.setFillAfter(true); view.startAnimation(alphaAnimation); alphaAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //动画结束,跳转 Intent intent = new Intent(MainActivity.this, HomeActivity.class); startActivity(intent); } @Override public void onAnimationRepeat(Animation animation) { } }); } }
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.example.daytwo" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' compile files('libs/xUtils-2.6.14.jar') compile 'com.android.support:design:26.0.0-alpha1' } android { useLibrary 'org.apache.http.legacy' }
来源:http://www.cnblogs.com/SLXN/p/7472073.html