Good day to all. I want to raise my level and learn how to make custom views. I thought at first to take TabLayout
and simply override the onDraw
method, onDraw
say, but immediately ran into a problem (most likely a lack of knowledge). In general, the problem is that after inheriting and redefining the onDraw
method in my class (MyTabLayout), I want all the other methods of the super class (TabLayout) to remain as they were, so what is my joint and how to do it? P.S. Sorry for the stupid question.
*/ public class MyTabLeyout extends TableLayout { private int mIndicatorLeft = -1; private int mIndicatorRight = -1; private int mSelectedIndicatorHeight; private final Paint mSelectedIndicatorPaint; private static final Pools.Pool<TabLayout.Tab> sTabPool = new Pools.SynchronizedPool<>(16); private final ArrayList<TabLayout.Tab> mTabs = new ArrayList<>(); public MyTabLeyout(Context context, Paint mSelectedIndicatorPaint) { super(context); this.mSelectedIndicatorPaint = new Paint(); } public int getTabCount() { return mTabs.size(); } private void setIndicatorPosition(int left, int right) { if (left != mIndicatorLeft || right != mIndicatorRight) { // If the indicator's left/right has changed, invalidate mIndicatorLeft = left; mIndicatorRight = right; ViewCompat.postInvalidateOnAnimation(this); } } void setSelectedIndicatorColor(int color) { if (mSelectedIndicatorPaint.getColor() != color) { mSelectedIndicatorPaint.setColor(color); ViewCompat.postInvalidateOnAnimation(this); } } void setSelectedIndicatorHeight(int height) { if (mSelectedIndicatorHeight != height) { mSelectedIndicatorHeight = height; ViewCompat.postInvalidateOnAnimation(this); } } @Override public void draw(Canvas canvas) { super.draw(canvas); // Thick colored underline below the current selection if (mIndicatorLeft >= 0 && mIndicatorRight > mIndicatorLeft) { canvas.drawCircle(mIndicatorLeft,getHeight() - mSelectedIndicatorHeight,10,mSelectedIndicatorPaint); // canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight, // mIndicatorRight, getHeight(), mSelectedIndicatorPaint); } } }
final MyTabLeyout tabLayout = (MyTabLeyout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("VIDEOS"));
final MyTabLeyout tabLayout = (MyTabLeyout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("VIDEOS"));
in that case,addTab
&&newTab
does not define methods - Diha-o