android 中自定义选项卡的问题

发布于 2024-10-22 14:22:00 字数 1661 浏览 1 评论 0原文

有人知道我需要包含什么图像才能消除图片中深红色选项卡底部的小银线吗?

带有银色底部边框的选项卡

这就是我更改选项卡背景的方式:

public void onCreate (Bundle savedInstanceState)
{
   ...
    setTabTheme();
    tabHost.setOnTabChangedListener (otc);   

   ...
}

// handler for tab changes to make sure our images are loaded
OnTabChangeListener otc = new OnTabChangeListener()
{
   @Override
   public void onTabChanged (String tabId)
   {
      setTabTheme();
   }
};


private void setTabTheme()
{
   tabHost = getTabHost();
   TabWidget twid = tabHost.getTabWidget();

   // set tab color
   for(int i=0; i < tabHost.getTabWidget().getChildCount(); i++)
   {
      // unselected icon
      Drawable tabd = (Drawable) getResources ().getDrawable (R.drawable.tabsel_dkred_big_9);
      tabHost.getTabWidget().getChildAt(i).setBackgroundDrawable (tabd);

      // need to figure out which one to make gray text...
      Log.d (TAG, "this widget focused : " + twid.isFocused ());

      // tab text
      RelativeLayout rLayout = (RelativeLayout) twid.getChildAt(i);

      if (rLayout.getChildCount () > 0)
      {
         TextView tv = ((TextView) rLayout.getChildAt(1));
         tv.setTextColor (Color.WHITE);

         // refer to res/style for text appearance
         tv.setTextAppearance(getBaseContext (), R.style.CustomText);
         Log.d (TAG, "text is " + tv.getText ().toString ());

      }
   }

   // set selected  tab
   Drawable tabd = (Drawable) getResources ().getDrawable (R.drawable.tabsel_red_big_9);
   tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundDrawable (tabd); 
}

Anyone know What image to I need to include to get rid of the small silver line at the bottom of the dark red tab in the picture?

tabs with silver bottom border

This is how I'm changing the tab background:

public void onCreate (Bundle savedInstanceState)
{
   ...
    setTabTheme();
    tabHost.setOnTabChangedListener (otc);   

   ...
}

// handler for tab changes to make sure our images are loaded
OnTabChangeListener otc = new OnTabChangeListener()
{
   @Override
   public void onTabChanged (String tabId)
   {
      setTabTheme();
   }
};


private void setTabTheme()
{
   tabHost = getTabHost();
   TabWidget twid = tabHost.getTabWidget();

   // set tab color
   for(int i=0; i < tabHost.getTabWidget().getChildCount(); i++)
   {
      // unselected icon
      Drawable tabd = (Drawable) getResources ().getDrawable (R.drawable.tabsel_dkred_big_9);
      tabHost.getTabWidget().getChildAt(i).setBackgroundDrawable (tabd);

      // need to figure out which one to make gray text...
      Log.d (TAG, "this widget focused : " + twid.isFocused ());

      // tab text
      RelativeLayout rLayout = (RelativeLayout) twid.getChildAt(i);

      if (rLayout.getChildCount () > 0)
      {
         TextView tv = ((TextView) rLayout.getChildAt(1));
         tv.setTextColor (Color.WHITE);

         // refer to res/style for text appearance
         tv.setTextAppearance(getBaseContext (), R.style.CustomText);
         Log.d (TAG, "text is " + tv.getText ().toString ());

      }
   }

   // set selected  tab
   Drawable tabd = (Drawable) getResources ().getDrawable (R.drawable.tabsel_red_big_9);
   tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundDrawable (tabd); 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文