2013.12.05(6)——— android ViewPagerIndicator之SampleTitlesDefault

package com.viewpagerindicator.sample;import android.os.Bundle;import android.support.v4.view.ViewPager;import com.viewpagerindicator.TitlePageIndicator;public class SampleTitlesDefault extends BaseSampleActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.simple_titles);        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());        mPager = (ViewPager)findViewById(R.id.pager);        mPager.setAdapter(mAdapter);        mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);        mIndicator.setViewPager(mPager);    }}



<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <com.viewpagerindicator.TitlePageIndicator        android:id="@+id/indicator"        android:padding="10dip"        android:layout_height="wrap_content"        android:layout_width="fill_parent"        />    <android.support.v4.view.ViewPager        android:id="@+id/pager"        android:layout_width="fill_parent"        android:layout_height="0dp"        android:layout_weight="1"        /></LinearLayout>



1、layout里面用的是
com.viewpagerindicator.TitlePageIndicator


2、title显示的名字会调用adapter的

getPageTitle



3、修改样式

xml
app:footerColor="#FFAA2222"        app:footerLineHeight="1dp"        app:footerIndicatorHeight="3dp"        app:footerIndicatorStyle="underline"        app:selectedColor="#FF000000"        app:selectedBold="true"


java

final float density = getResources().getDisplayMetrics().density;        indicator.setBackgroundColor(0x18FF0000);        indicator.setFooterColor(0xFFAA2222);        indicator.setFooterLineHeight(1 * density); //1dp        indicator.setFooterIndicatorHeight(3 * density); //3dp        indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);        indicator.setTextColor(0xAA000000);        indicator.setSelectedColor(0xFF000000);        indicator.setSelectedBold(true); 


BackgroundColor:tab的背景颜色FooterColor:tab最下面线的颜色FooterLineHeight:线的宽度FooterIndicatorHeight:处于选中状态时,线的宽度FooterIndicatorStyle:有三种样式 None(0) 无, Triangle(1)三角形, Underline(2) 下划线TextColor:tab上文字的颜色SelectedColor:处于选中状态时,文字的颜色SelectedBold:选中时,文字是否加粗





三角形的样式如下:





4、可以监听点击了正在显示的title 实现OnCenterItemClickListener
 @Override    public void onCenterItemClick(int position) {        Toast.makeText(this, "You clicked the center title!", Toast.LENGTH_SHORT).show();    }



5、监听活动和SampleCircles是一样的
//We set this on the indicator, NOT the pager        mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {            @Override            public void onPageSelected(int position) {                Toast.makeText(SampleTitlesWithListener.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();            }            @Override            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {            }            @Override            public void onPageScrollStateChanged(int state) {            }        });

更多相关文章

  1. android时间控件TimePicker使用实例
  2. Android(安卓)UI 常用颜色
  3. android布局layout边框颜色
  4. LinearLayout设置灰色边框,只保留底部边框,去掉三个框的技巧。
  5. Android(安卓)QQ通知小红点
  6. 2013.12.05(4)——— android ViewPagerIndicator之SampleLinesDef
  7. 改变滚动条的颜色ScrollView
  8. 简单有效的ItemDecoration--分割线
  9. Android中十六进制颜色字符串转int的方法

随机推荐

  1. Android(安卓)文件操作工具类
  2. Android(安卓)TimeUtile日期处理工具类(
  3. android Error inflating class com.goog
  4. Android(安卓)开发艺术探索 源码地址
  5. Android录音及播放功能实现
  6. Android折线图
  7. Android(安卓)ExpandableListView 可展开
  8. Android通过Mainfest设置Theme实现布局全
  9. Android中通过当前经纬度获得城市
  10. Android(安卓)smali语言功能指令详细介绍