2017-06-13 60 views
1

如何刪除分隔線數量選擇器,我試圖setShowDivider爲none(無,似乎不存在)通過XML和代碼注意到工作安卓:如何刪除分隔線數量拾取

picker.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); 

XML :

android:showDividers="none" 

enter image description here

+0

屏幕截圖可能會有幫助,也許 – Vucko

+0

確定添加,尖銳的,圍繞着1 – blackHawk

+0

的天藍色線條使其透明而不是刪除 –

回答

3

集的主題爲Numberpicker

<NumberPicker 
    ... 
    android:theme="@style/DefaultNumberPickerTheme" /> 

style.xml

<style name="DefaultNumberPickerTheme" parent="AppTheme"> 
     <item name="colorControlNormal">@color/transparent</item> 
</style> 

OR

private void changeDividerColor(NumberPicker picker, int color) { 

    java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields(); 
    for (java.lang.reflect.Field pf : pickerFields) { 
     if (pf.getName().equals("mSelectionDivider")) { 
      pf.setAccessible(true); 
      try { 
       ColorDrawable colorDrawable = new ColorDrawable(color); 
       pf.set(picker, colorDrawable); 
      } catch (IllegalArgumentException e) { 
       e.printStackTrace(); 
      } catch (Resources.NotFoundException e) { 
       e.printStackTrace(); 
      } 
      catch (IllegalAccessException e) { 
       e.printStackTrace(); 
      } 
      break; 
     } 
    } 
} 

,並設置爲

changeDividerColor(yournumberpicker, Color.parseColor("#00ffffff")); 
+0

遺憾的是沒有什麼 – blackHawk

+0

問題你面對? –

+0

它只是出現,因爲它是,你能告訴我如何訪問transpatent顏色,我應用白色,而不是它的工作,股息線出現 – blackHawk

0

該代碼會更好

private void changeDividerColor(NumberPicker picker, int color) { 
     try { 
      Field mField = NumberPicker.class.getDeclaredField("mSelectionDivider"); 
      mField.setAccessible(true); 
      ColorDrawable colorDrawable = new ColorDrawable(color); 
      mField.set(picker, colorDrawable); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    }