简体   繁体   English

如何在Android的PagerTitleStrip中为突出显示的标题打点

[英]How to make a dot for highlighted title in PagerTitleStrip in android

I am using PagerTitleStrip for swiping Fragment, I need to make a dot for selected item or Highlighted title. 我正在使用PagerTitleStrip刷片,我需要为所选项目或突出显示的标题打点。 My XML Code : 我的XML代码:

<android.support.v4.view.PagerTitleStrip
            android:id="@+id/pager_title_strip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="#fff"
            android:paddingBottom="6dp"
            android:paddingTop="6dp"
            android:textColor="@color/blueColorSwipeText" />

I also need to change the highlighted title color. 我还需要更改突出显示的标题颜色。 Please help me out. 请帮帮我。 Thanks Suggestions appreciated. 谢谢建议表示赞赏。

Use the textColor attribute; 使用textColor属性; Create a new style in res/values/styles.xml: 在res / values / styles.xml中创建新样式:

<style name="Pager">
    <item name="android:textColor">#4DB849</item>
    <item name="android:indicatorColor">#E95044</item>
</style>

You will get a green title and a red indicator. 您将获得一个绿色标题和一个红色指示器。

You may want to see ViewPagerIndicator 您可能需要查看ViewPagerIndicator

To change the indicator you have to change onDraw(Canvas canvas) method. 要更改指标,您必须更改onDraw(Canvas canvas)方法。
Here is the source code PagerTabStrip.java . 这是源代码PagerTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    final int height = getHeight();
    final int bottom = height;
    final int left = mCurrText.getLeft() - mTabPadding;
    final int right = mCurrText.getRight() + mTabPadding;
    final int top = bottom - mIndicatorHeight;

    mTabPaint.setColor(mTabAlpha << 24 | (mIndicatorColor & 0xFFFFFF));
    canvas.drawRect(left, top, right, bottom, mTabPaint);

    if (mDrawFullUnderline) {
        mTabPaint.setColor(0xFF << 24 | (mIndicatorColor & 0xFFFFFF));
        canvas.drawRect(getPaddingLeft(), height - mFullUnderlineHeight,
                getWidth() - getPaddingRight(), height, mTabPaint);
    }
}

You have to change this line: 您必须更改此行:

canvas.drawRect(left, top, right, bottom, mTabPaint);

Test if you get a dot when replacing with: 测试在替换为时是否出现点:

canvas.drawCircle(left, top, 15, mTabPaint);

For drawing custom views check out the Android documentation. 要绘制自定义视图,请查看Android文档。

Custom Drawing 定制图纸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM