Android 如何更改活动选项卡指示器的颜色?(安卓工作室)
我想知道我是否能够将活动选项卡指示器(浅蓝色线)的颜色更改为黑色(#4A4A4A)Android 如何更改活动选项卡指示器的颜色?(安卓工作室),android,tabs,Android,Tabs,我想知道我是否能够将活动选项卡指示器(浅蓝色线)的颜色更改为黑色(#4A4A4A) 如果您正在使用支持库。 将此添加到您的表格中 app:tabIndicatorColor="#4A4A4A" 公共类页面指示器扩展视图{ int totalNoOfDots; int-activeDot; 整数点间距; int水平空间=5; 位图活动点位图; 位图法线点位图; int x=0; 私人油漆; 公共页面指示器(上下文){ 超级(上下文); 油漆=新油漆(油漆.防油漆别名标志); activeDotB
如果您正在使用支持库。 将此添加到您的表格中
app:tabIndicatorColor="#4A4A4A"
公共类页面指示器扩展视图{
int totalNoOfDots;
int-activeDot;
整数点间距;
int水平空间=5;
位图活动点位图;
位图法线点位图;
int x=0;
私人油漆;
公共页面指示器(上下文){
超级(上下文);
油漆=新油漆(油漆.防油漆别名标志);
activeDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot\u活动);
normalDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot_normal);
}
公共页面指示器(上下文、属性集属性){
超级(上下文,attrs);
油漆=新油漆(油漆.防油漆别名标志);
activeDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot\u活动);
normalDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot_normal);
}
公共页面指示器(上下文上下文、属性集属性、int-defStyle){
超级(上下文、属性、定义样式);
油漆=新油漆(油漆.防油漆别名标志);
activeDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot\u活动);
normalDotBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dot_normal);
}
@凌驾
受保护的void onDraw(画布){
drawDot(帆布);
super.onDraw(帆布);
}
私有void drawDot(画布){
for(int i=0;i
在xml中调用该类,初始化pageindicator类后,您可以轻松更改页面指示符pageindicator=(pageindicator)findViewById(R.id.pageindicator);pageIndicator.setTotalNoOfDots(3);pageIndicator.setActiveDot(0);页面指示器。设置点间距(10);我用的是tabhost自动取款机
public class PageIndicator extends View {
int totalNoOfDots;
int activeDot;
int dotSpacing;
int horizontalSpace = 5;
Bitmap activeDotBitmap;
Bitmap normalDotBitmap;
int x = 0;
private Paint paint;
public PageIndicator(Context context) {
super(context);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
activeDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_active);
normalDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_normal);
}
public PageIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
activeDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_active);
normalDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_normal);
}
public PageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
activeDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_active);
normalDotBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dot_normal);
}
@Override
protected void onDraw(Canvas canvas) {
drawDot(canvas);
super.onDraw(canvas);
}
private void drawDot(Canvas canvas) {
for (int i = 0; i < totalNoOfDots; i++) {
if (i == activeDot) {
canvas.drawBitmap(activeDotBitmap, x, 0, paint);
} else {
canvas.drawBitmap(normalDotBitmap, x, 0, paint);
}
x = x + activeDotBitmap.getWidth() + horizontalSpace + dotSpacing;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = totalNoOfDots * (activeDotBitmap.getWidth() + horizontalSpace + getDotSpacing());
width = resolveSize(width, widthMeasureSpec);
int height = activeDotBitmap.getHeight();
height = resolveSize(height, heightMeasureSpec);
setMeasuredDimension(width, height);
}
public void refersh() {
x = 0;
invalidate();
}
public int getTotalNoOfDots() {
return totalNoOfDots;
}
public void setTotalNoOfDots(int totalNoOfDots) {
this.totalNoOfDots = totalNoOfDots;
x = 0;
invalidate();
}
public int getActiveDot() {
return activeDot;
}
public void setActiveDot(int activeDot) {
this.activeDot = activeDot;
x = 0;
invalidate();
}
public int getDotSpacing() {
return dotSpacing;
}
public void setDotSpacing(int dotSpacing) {
this.dotSpacing = dotSpacing;
x = 0;
invalidate();
}
}