2016-06-23 58 views
1

我的Android项目有问题。 我无法更改底部栏的颜色。
这是我多么希望我的bottombar看: wanted Like this更改背景颜色底部酒吧android

这是我的代码

菜单> tabhost_bottom.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 

> 
<item 
    android:id="@+id/home_item" 
    android:icon="@drawable/ic_home" 
    android:color="@color/colorPrimary" 
    android:title="Home" 
    /> 
<item 
    android:id="@+id/setting_item" 
    android:icon="@drawable/ic_setting" 
    android:color="@color/colorPrimary" 
    android:title="Setting" /> 

HomeActivity.java

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.tabhost_activity); 

    BottomBar bottomBar = BottomBar.attach(this, savedInstanceState); 
    bottomBar.setItemsFromMenu(R.menu.tabhost_bottom, new OnMenuTabSelectedListener() { 
     @Override 
     public void onMenuItemSelected(int itemId) { 

     } 
    }); 

    // Set the color for the active tab. Ignored on mobile when there are more than three tabs. 
    bottomBar.setActiveTabColor("#55a8e5"); 

    // Use the dark theme. Ignored on mobile when there are more than three tabs. 
    bottomBar.setBackgroundColor(Color.parseColor("#55a8e5")); 
    // Use custom text appearance in tab titles. 
    //bottomBar.setTextAppearance(R.style.MyTextAppearance); 

    // Use custom typeface that's located at the "/src/main/assets" directory. If using with 
    // custom text appearance, set the text appearance first. 
    //bottomBar.setTypeFace("MyFont.ttf"); 
} 

,这我参考

http://androidgifts.com/build-android-material-design-bottom-navigation/

+0

想改变标签的颜色? – Piyush

+0

yap,bottom tab – Haryanto

回答

0

当您使用this库(roughike的bottombar),你可以尝试这个。

您可以通过下面的行设置特定标签的backgroundColor:

bottomBar.getTabAtPosition(0).setBackgroundColor(backgroundColorInt); 

当您使用此行多次为每个标签,就可以改变整个标签的backgroundColor。

1

难道这就是library

其他选项:

好像你需要设置Background颜色以不同的方式:

// Setting colors for different tabs when there's more than three of them. 
    // You can set colors for tabs in three different ways as shown below. 
    mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorAccent)); 
    mBottomBar.mapColorForTab(1, 0xFF5D4037); 
    mBottomBar.mapColorForTab(2, "#7B1FA2"); 
    mBottomBar.mapColorForTab(3, "#FF5252"); 
    mBottomBar.mapColorForTab(4, "#FF9800"); 

更多inforation: Android new Bottom Navigation bar

+0

nope,这是不同的图书馆,但是谢谢 – Haryanto

+0

这篇文档? https://developer.android.com/reference/android/support/design/widget/TabLayout.html?utm_campaign=io15&utm_source=dac&utm_medium=blog – Flummox

+0

我使用这个http://androidgifts.c​​om/build-android-material-design -bottom-navigation/ – Haryanto

1

我终于实现了到变化它用下面的代码(Xamarin C#)

var bottomBarBackground = FindViewById(Resource.Id.bb_bottom_bar_background_view); 
bottomBarBackground.SetBackgroundResource(Resource.Drawable.tabbar_background); 

tabbar_background.axml:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/YourColor"/> 
     </shape> 
    </item> 
</layer-list> 

也发现在这里,虽然最终的解决方案并没有为我与Xamarin版本工作:Question about background color

+1

谢谢,这就是工作! – Haryanto