Last active
December 22, 2016 00:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.chamoapp.haegu; | |
... | |
public class CustomNumberPicker extends NumberPicker { | |
public CustomNumberPicker(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
NumberPicker numberpicker = null; | |
try { | |
numberpicker = (NumberPicker) findViewById(R.id.home_exchange_picker); | |
} catch (IllegalArgumentException e) { | |
e.printStackTrace(); | |
} | |
Class<?> numberPickerClass = null; | |
try { | |
numberPickerClass = Class.forName("android.widget.NumberPicker"); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
Field selectionDivider = null, selectionDividersDistance = null; | |
try { | |
selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider"); | |
selectionDividersDistance = numberPickerClass | |
.getDeclaredField("mSelectionDividersDistance"); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} | |
selectionDividersDistance.setAccessible(true); | |
selectionDivider.setAccessible(true); | |
Resources r = context.getResources(); | |
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, | |
16, r.getDisplayMetrics()); | |
try { | |
selectionDividersDistance.set(numberpicker, (int) px); | |
selectionDivider.set(numberpicker, getResources() | |
.getDrawable(R.color.numberpicker_divider_color)); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} catch (IllegalArgumentException e) { | |
e.printStackTrace(); | |
} catch (NotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
@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); | |
updateView(child); | |
} | |
@Override | |
public void addView(View child, android.view.ViewGroup.LayoutParams params) { | |
super.addView(child, params); | |
updateView(child); | |
} | |
private void updateView(View view) { | |
if (view instanceof EditText) { | |
((EditText) view).setTextSize(12); | |
((EditText) view).setTextColor(Color.parseColor("#FFFFFF")); | |
((EditText) view).setEnabled(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment