android 自带的design包中tablayout使用
来源:互联网 发布:婚纱摄影后期软件 编辑:程序博客网 时间:2024/06/01 07:43
在studio的Project Structure=>app=>dependencies ==>搜索design的依赖,如下:
compile 'com.android.support:design:26.0.0-alpha1'
先看实现的效果
先看一下布局吧(这个是activity中的主布局,也就是tabyaout,替换的布局是fragment )
<?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" android:orientation="vertical" android:background="#F8F8F8" android:id="@+id/linear" tools:context="com.yangzhuokeji.myapplication.MainActivity"> <android.support.design.widget.TabLayout android:background="@android:color/white" android:layout_marginTop="5dp" android:id="@+id/tab" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="#3082B4" android:enabled="false" app:tabTextColor="@android:color/black" app:tabSelectedTextColor="#3082B4" app:tabMode="fixed" /> <android.support.v4.view.ViewPager android:layout_marginTop="10dp" android:background="@android:color/white" android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
MainActivity.class
import android.support.design.widget.TabLayout;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.content.ContextCompat;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.LinearLayout;public class MainActivity extends AppCompatActivity { private LinearLayout linearLayout; Fragment[] fragments = {new BlankFragment(), new Blank2Fragment(), new Blank3Fragment(), new Blank4Fragment()}; String[] titles = {"全部", "已通过", "审核中", "未通过"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabLayout tab = (TabLayout) findViewById(R.id.tab); linearLayout = (LinearLayout) findViewById(R.id.linear); //添加tablayout中的竖线 LinearLayout linearLayout = (LinearLayout) tab.getChildAt(0); linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); linearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider)); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return fragments[position]; } @Override public int getCount() { return fragments.length; } @Override public CharSequence getPageTitle(int position) { return titles[position]; } }); tab.setupWithViewPager(viewPager); }}
viewPager.setCurrentItem(tabposition);tab.getTabAt(tabposition).select();跳转到指定的位置
tablayout每个item的分割线(竖线)
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#80c0c0c0"/> <size android:width="1dp"/></shape>fragment就给一个例子吧,其他的都一样,自己做服务器对接交互就行了
import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * A simple {@link Fragment} subclass. */public class BlankFragment extends Fragment { public BlankFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_blank, container, false); }}自己做个记录,有需要的,自己看哈,挺简单的
1 0
- android 自带的design包中tablayout使用
- Android M源码中使用android.support.design包的TabLayout
- 关于Design包中TabLayout+ViewPager的简单使用
- design包中的tablayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- android.support.design.widget.TabLayout的使用
- 使用Android自带的material design图标
- Android L、M扩展支持包design中widget:TabLayout
- Android design包自定义tablayout的底部导航栏
- Design库-TabLayout的使用
- TabLayout的使用(design)
- android的design库-----TabLayout的简单使用
- Android Design Support Library(4)- TabLayout的使用
- Android系统启动过程
- 2017.4.17
- Android 新特性整理
- SuperMap iCloudManager OpenStack平台部署指南
- MyBatis嵌套查询解析
- android 自带的design包中tablayout使用
- 使用FastJSON,将对象或数组和JSON串互转
- ZOJ Problem Set
- 使用git上传本地代码到github上
- 简单错误记录(LinkedHashMap:有顺序的存和取)
- Aspose.Cell 导出Excel
- 怎么才能做一个成功的微商!
- 最小费用流
- 0417