Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.taxiexchange.widgets.timepicker;
- import android.content.Context;
- import android.content.res.Resources;
- import android.graphics.Color;
- import android.graphics.Typeface;
- import android.util.AttributeSet;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.NumberPicker;
- import com.taxipixi.taxiexchange.R;
- import java.lang.reflect.Field;
- /**
- * Created by Administrator on 4/9/2016.
- */
- public class HourNumberPicker extends NumberPicker {
- Typeface type;
- public HourNumberPicker(Context context, AttributeSet attrs) {
- super(context, attrs);
- processAttributeSet(attrs);
- Class<?> numberPickerClass = null;
- try {
- numberPickerClass = Class.forName("android.widget.NumberPicker");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Field selectionDivider = null;
- try {
- selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- try {
- selectionDivider.setAccessible(true);
- selectionDivider.set(this, getResources().getDrawable(R.color.colorSelector));
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (Resources.NotFoundException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- private void processAttributeSet(AttributeSet attrs) {
- //This method reads the parameters given in the xml file and sets the properties according to it
- this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
- this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
- }
- @Override
- public void addView(View child) {
- super.addView(child);
- updateView(child);
- }
- @Override
- public void addView(View child, int index,
- android.view.ViewGroup.LayoutParams params) {
- super.addView(child, index, params);
- type = Typeface.createFromAsset(getContext().getAssets(),
- "fonts/NeoSansCyr-Light.ttf");
- updateView(child);
- }
- @Override
- public void addView(View child, android.view.ViewGroup.LayoutParams params) {
- super.addView(child, params);
- type = Typeface.createFromAsset(getContext().getAssets(),
- "fonts/NeoSansCyr-Light.ttf");
- updateView(child);
- }
- private void updateView(View view) {
- if (view instanceof EditText) {
- ((EditText) view).setTypeface(type);
- ((EditText) view).setTextSize(30);
- //((EditText) view).setTextColor(getResources().getColor(R.color.colorPrimary));
- ((EditText) view).setTextColor(Color.BLACK);
- ((EditText) view).setFocusable(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment