TypedArray ta = context.getTheme().obtainStyledAttributes(R.style.TextAppearance, new int[] { android.R.attr.textSize }); float textSize = ta.getFloat(0, 12f); ta.recycle(); TextView textView = findViewById(R.id.tvExample); textView.setTextSize(textSize);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LineView); float startX = ta.getFloat(R.styleable.LineView_startX, 0f); float startY = ta.getFloat(R.styleable.LineView_startY, 0f); ta.recycle(); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(5f); canvas.drawLine(startX, startY, 100f, 100f, paint);In both examples, the package library used is android.content.res.