Skip to content

Commit

Permalink
Fix Exception Wrong Cast
Browse files Browse the repository at this point in the history
  • Loading branch information
dargoz committed Feb 24, 2021
1 parent 2aa68cc commit cb395b4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ Release tag notes:
- enhance subMenu constraint validation on right corner

- v 0.4.2
- add capability to replace menu title text to ImageView
- add capability to replace menu title text to ImageView

- v 0.4.3
- Fix exception Cannot Cast ImageView to TextView due to replacement View using method replaceMenuTextToImage(..)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class MainActivity : AppCompatActivity() {
val bottomNavBar = findViewById<BottomNavigationBar>(R.id.bottom_navigation_menu)
bottomNavBar.addSubMenu(R.menu.sub_menu_navigation_list, 1, SubMenuOrientation.VERTICAL)
bottomNavBar.setSubMenuTextColor(R.color.colorPrimaryDark)

bottomNavBar.setMenuOnClickListener { menu, position ->
Log.i("DRG", "menu : ${menu.getItem(position).title} :: pos : $position")
visibility = !visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity() {
}
}
bottomNavBar.replaceMenuTextToImage(2, R.drawable.baseline_credit_card_black_18)
bottomNavBar.setHighlightMenuPosition(2)
bottomNavBar.addSubMenu(R.menu.sub_menu_navigation_list, 4, SubMenuOrientation.VERTICAL)
bottomNavBar.setSubMenuTextColor(R.color.colorPrimaryDark)
bottomNavBar.showSubMenu(4, false)
Expand Down
2 changes: 1 addition & 1 deletion extendedbottomnavigationview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
buildToolsVersion "29.0.2"


defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ public void setSubMenuOnClickListener(MenuOnClickListener subMenuOnClickListener
public void setHighlightMenuPosition(int position) {
this.highlightMenuPosition = position;
LinearLayout menuLayout = getMenuChildAt(position);
TextView titleText = (TextView) menuLayout.getChildAt(1);
titleText.setTextSize(TypedValue.DENSITY_DEFAULT, getResources().getDimensionPixelSize(R.dimen.highlight_text_size));
titleText.setSelected(true);
View titleTextView = menuLayout.getChildAt(1);
if (titleTextView instanceof TextView) {
Log.d("DRG","textView");
((TextView)titleTextView)
.setTextSize(
TypedValue.DENSITY_DEFAULT,
getResources().getDimensionPixelSize(R.dimen.highlight_text_size));

}
titleTextView.setSelected(true);
}

public void replaceMenuTextToImage(int position, int imageResourceId) {
Expand Down Expand Up @@ -392,8 +399,11 @@ private void setItemsTextColor(int menuItemTextColor) {
R.color.default_color_state : menuItemTextColor);
for (int i = 0; i < menu.size(); i++) {
LinearLayout menuLayout = getMenuChildAt(i);
TextView textView = (TextView) menuLayout.getChildAt(1);
textView.setTextColor(colorStateList);
View titleView = menuLayout.getChildAt(1);
if(titleView instanceof TextView) {
((TextView)titleView).setTextColor(colorStateList);
}

}
}

Expand All @@ -416,7 +426,7 @@ private void setMenuSelected(int itemIndex, boolean flagSelected) {
LinearLayout menuLayout = getMenuChildAt(itemIndex);
int imageId = imageIconIds.get(itemIndex,-1);
ImageView imageIcon = menuLayout.findViewById(imageId);
TextView titleText = (TextView) menuLayout.getChildAt(1);
View titleText = menuLayout.getChildAt(1);
imageIcon.setSelected(flagSelected);
titleText.setSelected(flagSelected);
}
Expand Down

0 comments on commit cb395b4

Please sign in to comment.