From a96f3f6cfd7f1bdd66b46b8a438297845ea1242a Mon Sep 17 00:00:00 2001 From: Arvind Menon Date: Fri, 23 Sep 2016 11:48:30 -0500 Subject: [PATCH 1/2] Fixed setting items programatically --- .../com/example/bottombar/sample/ThreeTabsActivity.java | 3 ++- app/src/main/res/layout/activity_three_tabs.xml | 5 ++--- .../src/main/java/com/roughike/bottombar/BottomBar.java | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/bottombar/sample/ThreeTabsActivity.java b/app/src/main/java/com/example/bottombar/sample/ThreeTabsActivity.java index b83334c5..c1527fef 100644 --- a/app/src/main/java/com/example/bottombar/sample/ThreeTabsActivity.java +++ b/app/src/main/java/com/example/bottombar/sample/ThreeTabsActivity.java @@ -25,6 +25,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { messageView = (TextView) findViewById(R.id.messageView); BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar); + bottomBar.setItems(R.xml.bottombar_tabs_three); bottomBar.setOnTabSelectListener(new OnTabSelectListener() { @Override public void onTabSelected(@IdRes int tabId) { @@ -39,4 +40,4 @@ public void onTabReSelected(@IdRes int tabId) { } }); } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/activity_three_tabs.xml b/app/src/main/res/layout/activity_three_tabs.xml index e1684096..87887ee1 100644 --- a/app/src/main/res/layout/activity_three_tabs.xml +++ b/app/src/main/res/layout/activity_three_tabs.xml @@ -16,7 +16,6 @@ android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="60dp" - android:layout_alignParentBottom="true" - app:bb_tabXmlResource="@xml/bottombar_tabs_three" /> + android:layout_alignParentBottom="true"/> - \ No newline at end of file + diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index fc54174d..7094a3c8 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -107,7 +107,9 @@ public BottomBar(Context context) { public BottomBar(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); - setItems(tabXmlResource); + if (tabXmlResource != 0) { + setItems(tabXmlResource); + } } private void init(Context context, AttributeSet attrs) { @@ -256,6 +258,7 @@ private void updateItems(final List bottomBarItems) { int index = 0; int biggestWidth = 0; + tabContainer.removeAllViews(); BottomBarTab[] viewsToAdd = new BottomBarTab[bottomBarItems.size()]; for (BottomBarTab bottomBarTab : bottomBarItems) { @@ -853,4 +856,4 @@ private void toggleShyVisibility(boolean visible) { from.setHidden(this, visible); } } -} \ No newline at end of file +} From 8de557934396c626ec8a94716c8b0764685c4208 Mon Sep 17 00:00:00 2001 From: Arvind Menon Date: Fri, 23 Sep 2016 11:58:20 -0500 Subject: [PATCH 2/2] Moved tab resource check to init method --- .../src/main/java/com/roughike/bottombar/BottomBar.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index 7094a3c8..3dbcc70f 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -107,15 +107,15 @@ public BottomBar(Context context) { public BottomBar(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); - if (tabXmlResource != 0) { - setItems(tabXmlResource); - } } private void init(Context context, AttributeSet attrs) { populateAttributes(context, attrs); initializeViews(); determineInitialBackgroundColor(); + if (tabXmlResource != 0) { + setItems(tabXmlResource); + } } private void populateAttributes(Context context, AttributeSet attrs) {