2011-02-11 49 views
0

我有一個基本的TabActivity。在android 2.1上(可能還有舊版本),它看起來像在選項卡小部件下面添加了陰影。在2.3上,這個影子不存在。有沒有辦法將這個陰影徹底消失?也許像「android:fadingEdgeLength = 0」?TabHost - 擺脫陰影?

謝謝

回答

1

你說的是白色條紋嗎?我砍死過去通過調用這個方法裏面onTabChanged

讓你的類實現OnTabChangeListener

private static TabHost mTabHost; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
     // Instantiate your tab host normally 
} 


@Override 
    public void onTabChanged(String tabId) { 
     removeWhiteStrip(mTabHost); 
} 

/** 
* Hack 
* @param tabHost 
*/ 
private static void removeWhiteStrip(TabHost tabHost) { 
    TabWidget tw = (TabWidget) tabHost.getChildAt(1); 

    Field mBottomLeftStrip; 
    Field mBottomRightStrip; 

    try { 
     mBottomLeftStrip = tw.getClass().getDeclaredField("mBottomLeftStrip"); 
     mBottomRightStrip = tw.getClass().getDeclaredField("mBottomRightStrip"); 

     if (!mBottomLeftStrip.isAccessible()) { 
      mBottomLeftStrip.setAccessible(true); 
     } 

     if (!mBottomRightStrip.isAccessible()) { 
      mBottomRightStrip.setAccessible(true); 
     } 

// This is a blank drawable basically a 1x1 png with 100% alpha 
     mBottomLeftStrip.set(tw, MyApp.getInstance().getResources().getDrawable(R.drawable.blank)); 
     mBottomRightStrip.set(tw, MyApp.getInstance().getResources().getDrawable(R.drawable.blank)); 

    } 
    catch (java.lang.NoSuchFieldException e) { 
     // possibly 2.2 
     try { 
      Method stripEnabled = tw.getClass().getDeclaredMethod("setStripEnabled", boolean.class); 
      stripEnabled.invoke(tw, false); 

     } 
     catch (Exception e1) { 
      e1.printStackTrace(); 
     } 
    } 
    catch (Exception e) { 
     // tut tut shouldn't catch generic exception and ignore it 
      // but we do because this is a hack 
    } 

} 

享受

+0

嗨呀 - 我使用的是光的主題,讓陰影我認爲,看起來是黑色而不是白色。黑客不工作,陰影仍然顯示。實際上只有在其中一個孩子是活動,而不是ListActivity時才顯示,這很奇怪。 Argh,android ... – user291701 2011-02-11 21:55:21