2017-01-12 2 views
0

Я использую грубую смесь, чтобы перемещаться по фрагментам в моем проекте, я пытаюсь установить привлекательный фон для моего узла, но с этим трудно справиться. Пример в официальном руководстве https://github.com/roughike/BottomBar показывает только, как изменить цвет панели. Есть ли способ сделать это?Установите черновой дымоходный фонарик

resId = R.drawable.footer_bg_02; 
    bottomBar = BottomBar.attach(this, savedInstanceState); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 
     bottomBar.setBackground(resId); 
    } 
    bottomBar.setFragmentItems(getSupportFragmentManager(), R.id.fragmentContainer, 
      new BottomBarFragment(StoreList.newInstance("Content for fragment 1."), R.drawable.ic_01, "fragment 1"), 
      new BottomBarFragment(QRscanner.newInstance("Content for fragment 2."), R.drawable.ic_02, "fragment 2"), 
      new BottomBarFragment(MyBooking.newInstance("Content for fragment 3."), R.drawable.ic_03, "fragment 3"), 
    ); 

    bottomBar.setOnItemSelectedListener(new OnTabSelectedListener() { 
     @Override 
     public void onItemSelected(int position) { 
      switch (position) { 
       case 0: 
        getSupportActionBar(); 
        //return; 
       case 1: 
        //getSupportActionBar().hide(); 
       case 2: 
        //return; 
       case 3: 
        //getSupportActionBar().hide(); 
       case 4: 
        //return; 
        // Item 1 Selected 
      } 
     } 
    }); 

Я пытаюсь использовать setBackground, но не могу получить удачу.

ответ

0

Это предложение от issue, вы можете использовать, как это:

<com.roughike.bottombar.BottomBar 
    android:id="@+id/bottomBar" 
    android:layout_width="match_parent" 
    android:layout_height="60dp"  
    android:background="@color/colorAccent" 
    android:layout_alignParentBottom="true" 
    app:bb_tabXmlResource="@xml/bottombar_tabs" /> 
0

попробовать это: добавить это к родительскому макете:

xmlns:app="http://schemas.android.com/apk/res-auto" 

затем

<com.roughike.bottombar.BottomBar 
     android:id="@+id/bottomBar" 
     android:layout_width="match_parent" 
     android:layout_height="70dp" 
     android:layout_alignParentBottom="true" 
     app:bb_activeTabAlpha="1" 
     app:bb_activeTabColor="@color/color_white" 
     app:bb_behavior="shifting" 
     app:bb_inActiveTabAlpha="0.6" 
     app:bb_inActiveTabColor="#1B5E20" 
     app:bb_tabXmlResource="@xml/bottombar_tabs" 
     app:bb_titleTextAppearance="@style/style_text" 
     app:paddingEnd="0dp" /> 

в вашем разрешении/папку XML:

bottombar_tabs.xml пишут:

<?xml version="1.0" encoding="utf-8"?> 
<tabs> 
    <tab 
     icon="@drawable/drawable1" 
     id="@+id/areas_item" 
     title="HOME" /> 
    <tab 
     icon="@drawable/drawable2" 
     id="@+id/nearby_item" 
     title="Nearby" /> 
    <tab 
     icon="@drawable/drawable3" 
     id="@+id/my_marker_item" 
     title="My marker" /> 

</tabs> 

это стиль:

<style name="style_text"> 
    <item name="android:textSize">12sp</item> 
    <item name="android:textColor">@color/color_white</item> 
    <item name="android:textStyle">bold</item> 
</style> 

Для programetically использовать элементы настройки:

bottomBar = BottomBar.attach(this, savedInstanceState); 

    bottomBar.setFragmentItems(getSupportFragmentManager(), R.id.fragmentContainer, 
      new BottomBarFragment(SampleFragment.newInstance("Content for recents."), R.drawable.home, "Recents"), 
      new BottomBarFragment(SampleFragment.newInstance("Content for food."), R.drawable.food, "Food"), 
      new BottomBarFragment(SampleFragment.newInstance("Content for favorites."), R.drawable.favourite, "Favorites"), 
      new BottomBarFragment(SampleFragment.newInstance("Content for locations."), R.drawable.location, "Location") 
    ); 

    // Setting colors for different tabs 
    bottomBar.mapColorForTab(0, "#3B494C"); 
    bottomBar.mapColorForTab(1, "#00796B"); 
    bottomBar.mapColorForTab(2, "#7B1FA2"); 
    bottomBar.mapColorForTab(3, "#FF5252"); 

    bottomBar.setOnItemSelectedListener(new OnTabSelectedListener() { 
     @Override 
     public void onItemSelected(int position) { 
      switch (position) { 
       case 0: 
        // Item 1 Selected 
      } 
     } 
    }); 
+0

Есть ли способ установить его программно? Так как я не создал нижнюю панель в моем файле макета, то узел был создан непосредственно из моей активности. – JerryKo

+0

@JerryKo см. Edit..actuall y i не найти никакого способа изменить drawable ... вы можете изменить только цвет – rafsanahmad007

0

Я понял это.

BottomBar bBar = (BottomBar) findViewById(R.id.bottomBar); 
bBar.setOnTabSelectListener(this); 

BottomBarTab tab1 = bBar.getTabAtPosition(0); 
tab1.setBarColorWhenSelected(Color.WHITE) 
BottomBarTab tab2 = bBar.getTabAtPosition(1); 
tab2.setBarColorWhenSelected(Color.WHITE) 

bBar.selectTabAtPosition(0) 

Это немного неуклюжий, но он работает. Просто установите любой цвет, который вы хотите, и он будет обновляться программно.

Смежные вопросы