BottomNavigationView showing items problem - android

I use BottomNavigationView in my app (modified from sample project) and I want to change the items in the container. I have 4 items within the container, 5 including the BottomNavigationView. I only want to display 2 items when apps is first start. Then show another 2 items and hide the previous 2 items when one of the Button in BottomNavigationView is clicked.
How to do it?

to hide any view button,textview or edittext just use this code on the button click
view.setVisibility(GONE)
GONE hides the whole view even the height and the width of the view
view.setVisibility(INVISIBLE)
INVISIBLE only hides the content but preserves the height and the width

boolean state; // define boolean variable
home.setVisibility(View.GONE);
info.setVisibility(View.GONE);
In your botton navigation click listener just use
b2.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
if ( state )
{
state = false;
home.setVisibility(View.VISIBLE);
info.setVisibility(View.VISIBLE);
}
else
{
state = true;
home.setVisibility(View.GONE);
info.setVisibility(View.GONE);
}
}
}

Related

How to disable all clickable items in AppBarLayout?

I'm trying to disable all clickable items in the app bar layout when the opaque background appears after clicking the floating action button. But I also need to make sure that all the floating action buttons are all still clickable. I'm thinking maybe I can disable all items in the app bar programmatically?
How to achieve this?
UPDATE
Code to set fab visibility and animation. When the Fabs displayed, the tabs and toolbar finally disabled and unclickable. But i want to make my Fabs still clickable. How can i do this? Please advice. Thank you!
public void fabVisibility(){
if (isOpen){
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
fabActivity.startAnimation(fabClose);
textViewActivities.startAnimation(fabClose);
fabPost.startAnimation(fabClose);
textViewPosts.startAnimation(fabClose);
fabMedia.startAnimation(fabClose);
textViewMedia.startAnimation(fabClose);
fabPlus.startAnimation(fabRotateAntiClockwise);
fabActivity.setClickable(false);
fabPost.setClickable(false);
fabMedia.setClickable(false);
shadowView.setVisibility(View.INVISIBLE);
isOpen = false;
}else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
fabActivity.startAnimation(fabOpen);
textViewActivities.startAnimation(fabOpen);
fabPost.startAnimation(fabOpen);
textViewPosts.startAnimation(fabOpen);
fabMedia.startAnimation(fabOpen);
textViewMedia.startAnimation(fabOpen);
fabPlus.startAnimation(fabRotateClockwise);
fabPlus.setEnabled(true);
fabActivity.setClickable(true);
fabActivity.setEnabled(true);
fabPost.setClickable(true);
fabPost.setEnabled(true);
fabMedia.setClickable(true);
fabMedia.setEnabled(true);
shadowView.setVisibility(View.VISIBLE);
isOpen = true;
}
}
To disable the user interaction you just need to add the following code
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
To get user interaction back you just need to add the following code
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
To disable action bar (app bar) buttons on clicking FAB icon, you could set a flag, let's say DisableAppBarButton.
Now call invalidateOptionsMenu() which will trigger onCreateOptionsMenu and will regenerate your menu.
Modify your onCreateOptionsMenu to disable the buttons.
if (DisableAppBarButton) {
menu.someItem(R.id.yourItem).setEnabled(false);
} else {
menu.someItem(R.id.yourItem).setEnabled(true);
}
Two options:
1 - You can set a view group to be disabled by recursively setting all of its children disabled. Example:
public static setEnabled(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
setEnabled(viewGroup.getChild(i), enabled);
}
}
}
Then in your code in response to the FAB showing or hiding:
ViewUtil.setEnabled(mAppBarLayout, true /* or false */);
2 - You can make the opaque background focusable and clickable to intercept clicks while it's overlayed over the app bar, while the FAB buttons that float above that background would still receive clicks.
Hope that helps!

Activate or de activate recyclerview items

I have a fragment which contains a recyclerview and a floating action button. In recyclerview, each row contains a radio button set as disabled by default. my requirement is I need to enable these radio buttons in every row upon floating action button click event. Is there any solution?
Thanks in advance..
OK... I got a solution.
here is my code.
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
for (int i = 0; i <= adapter.getItemCount(); i++) {
View childVIew = recyclerView.getChildAt(i);
if (childVIew != null) {
RadioButton radioYes = childVIew.findViewById(R.id.radio_yes_my_health_info);
radioYes.setEnabled(true);
RadioButton radioNo = childVIew.findViewById(R.id.radio_no_my_health_info);
radioNo.setEnabled(true);
}
}
fab.setImageResource(R.drawable.ic_save_white_24dp);
recyclerView.getRecycledViewPool().setMaxRecycledViews(0, 0);
}
});
Now on FAB button click, all the radio buttons inside my recyclerview will be enabled and I can click to change the state of every radio button. But here I have got a problem. When I click FAB button, all the radio buttons inside the recyclerview will be activated but when I scroll the recyclerview all those radio buttons will be disabled or deactivated again. Please give me a solution for this.
You can have a flag in your adapter like
boolean isActivated = false;
public void setActivated(boolean activated) {
isActivated = activated;
}
and in your onBindViewHolder() method you can check for the flag and set the state of your flag accordingly.
In the OnClickListener of your FAB, call
adapter.setActivated(true);//true or false as per your requirement
adapter.notifyDataSetChanged();
This should work.
You can try looping through every view when you click the button, like so:
for (int i = 0; i < adapter.getItemCount(); i++) {
View view = recycler.getLayoutManager().findViewByPosition(i);
view.setSelected(true); //Select item
notifyItemChanged(i); //Notify item changed
}

How to replace the actionbar by a popup menu?

I want to achieve 1 of these options for my EditText :
Replace the actionbar that appear on the top by a popup menu instead. Something like this for exemple:
Or make the actionbar floating and child of my current view (in some way same a first option)
i need this because i add my view via windowManager.addView(view, Layout_Params); and in this way i have some trouble with the actionbar on the top (it is displayed blank)
actually i do this to show the actionbar :
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
Activity host = (Activity) this.getContext();
return host.getWindow().getDecorView().startActionMode(callback);
}
but it's don't work, it's show me an empty white actionbar on the stop instead :( i think i need to create myself the ActionMode but i don't know how to do it.
Ok. You can hide the actionbar when your edittext is gained focus. Then you need to show the popup menu where ever you want.
EditText t = new EditText(this);
t.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b){
getSupportActionBar().hide();
//now show your popup menu at the top position
}else{
getSupportActionBar().show();
//here you dismiss the menu.
}
}
});

How to design android layout for this snapshot?

I am a new in android programming, I made a layout with this figure:
Now I want to know when one of these buttons clicked I should run an new activity or change visibility to false and show new layout without run a new activity, what is the best solution?
You consider that count of these buttons are more than ten.
I want show a text with image,..(when clicked) because that is a educational book and these buttons are chapters list of that book
for an example if you want to change only the layout then you could do something like this
FirstButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
FirstView();
}
});
/
void FirstView(){
setContentView(R.layout.yourOtherLayout);
// then declare the layout views here.
firstView=false;
}
you can do this in all the buttons just create different methods for each
to handle the Back Button you can declare Boolean variables and use If else Statement to loop through them for example
boolean firstView = true, secondView = true;
#Override
public void onBackPressed(){
if (firstView == false ){
then firstView Is Showing.
// show the view you want and set
firstView = true;
}else if (SO ON)...
else { super.OnBackPressed(); // exit }
}

Make one layout inside the main layout invisible when we click other area on the main layout

I have one custom listview containing imagebuttons and textviews. Right now when I click on the info icon, it opens up the pop up(which is actually a layout that I am making visible on the imagebutton's click) that gives some description and when I click on that icon again it becomes invisible. But I want it to make invisible whenever I click on any other area and not just on that info icon.
//img_Info is the Imagebutton containing i icon
img_Info = (ImageButton)view.findViewById(R.id.img_Info);
img_Info.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//llimg_info is the linearlayout that becomes visible on the click event
if(llimg_info.isShown()) {
llimg_info.setVisibility(llimg_info.INVISIBLE);
}
else {
llimg_info.setVisibility(llimg_info.VISIBLE);
}
}
});
Any suggestions please?
Please try below code for check visibility of ImageView, it will solve your problem.
ImageView llimg_info = (ImageView) findViewById(R.id.img_Info);
if (llimg_info.getVisibility() == 0) {
System.out.println("Visible");
llimg_info.setVisibility(llimg_info.INVISIBLE);
} else{
System.out.println("Invisible");
llimg_info.setVisibility(llimg_info.VISIBLE);
}
Not sure if it will help, but try to register a focus change listener for your pop-up, so that when it will loose focus to make it invisible.
Something like this:
thePopup.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
thePopup.setVisibility(View.GONE);
}
}
});

Categories

Resources