<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="color_theme">#489cfa</color> <color name="transparent">#00000000</color> <color name="yellow">#fc9630</color> </resources>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mly.panhouye.pagerslidingtabstripdemo.MainActivity">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/pst"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/color_theme"
app:pstsShouldExpand="true"
app:pstsTabBackground="@color/transparent"
app:pstsIndicatorHeight="5dp"
app:pstsIndicatorColor="@color/yellow"
app:pstsTextAllCaps="false"
app:pstsUnderlineHeight="15dp"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/pst"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="潘"
android:textSize="100sp"
/>
</LinearLayout>
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by panchengjia on 2017/1/15 0015.
*/
public class HouFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_hou,null);
return view;
}
}
package com.mly.panhouye.pagerslidingtabstripdemo;
import android.os.Bundle;
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.v7.app.AppCompatActivity;
import com.astuetz.PagerSlidingTabStrip;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
PagerSlidingTabStrip pst;
ViewPager viewPager;
ArrayList<Fragment> fragments;
//声明pst的标题
String[] titles = {"潘","侯","爷"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pst= (PagerSlidingTabStrip) findViewById(R.id.pst);
viewPager= (ViewPager) findViewById(R.id.pager);
fragments = new ArrayList<>();
HouFragment houFragment = new HouFragment();
PanFragment panFragment = new PanFragment();
YeFragment yeFragment = new YeFragment();
//添加fragment到集合中时注意顺序
fragments.add(panFragment);
fragments.add(houFragment);
fragments.add(yeFragment);
FragmentManager fragmentManager = getSupportFragmentManager();
viewPager.setAdapter(new MyPagerAdapter(fragmentManager,titles,fragments));
viewPager.setCurrentItem(0);
//当ViewPager的onPagerChangeListener回调时,PagerSlidingTabStrip也一起随之变动
//具体做法都已封装到了PagerSlidingTabStrip.setViewPager()方法里,使用时调用实例如下
pst.setViewPager(viewPager);
pst.setTextSize(30);
}
/**
* 自定义适配器
*/
class MyPagerAdapter extends FragmentPagerAdapter {
private String[] titles;
ArrayList<Fragment> fragments;
//根据需求定义构造方法,方便外部调用
public MyPagerAdapter(FragmentManager fm, String[] titles, ArrayList<Fragment> fragments) {
super(fm);
this.titles = titles;
this.fragments = fragments;
}
//设置每页的标题
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
//设置每一页对应的fragment
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
//fragment的数量
@Override
public int getCount() {
return fragments.size();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有