package com.viewpagerindicator.sample; import android.os.Bundle; import android.support.v4.view.ViewPager; import com.viewpagerindicator.UnderlinePageIndicator; public class SampleUnderlinesDefault extends BaseSampleActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_underlines); mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (UnderlinePageIndicator)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"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> <com.viewpagerindicator.UnderlinePageIndicator android:id="@+id/indicator" android:layout_height="2dp" android:layout_width="fill_parent" /> </LinearLayout>
1、注意layout里面的是
com.viewpagerindicator.UnderlinePageIndicator
2、设置下划线不消失
indicator.setFades(false);
3、修改样式
xml
app:selectedColor="#FFCC0000" app:fadeDelay="1000" app:fadeLength="1000"
java
indicator.setViewPager(mPager); indicator.setSelectedColor(0xFFCC0000); indicator.setBackgroundColor(0xFFCCCCCC); indicator.setFadeDelay(1000); indicator.setFadeLength(1000);
SelectedColor:下划线的颜色 FadeDelay:下划线多长时间消失 FadeLength:不懂。。。