I would like to have a Floating Action Button (FAB) that when clicked would expand and display more options, which could be navigated by draging your finger, like with the android lock ring.
I have found some libraries that replicate the lock ring, but they are not what I'm looking for.
Is it possible to implement this behaviour with a FAB?
You can do the same with hiding and showing FAB programmatically
#OnClick(R.id.expand)
public void onExpand(View view) {
Utils.hideKeyboard(this);
if (isFabOpen) {
expand.startAnimation(rotateBackward);
facebook.startAnimation(fabClose);
twitter.startAnimation(fabClose);
signUp.startAnimation(fabClose);
} else {
expand.startAnimation(rotateForward);
facebook.startAnimation(fabOpen);
twitter.startAnimation(fabOpen);
signUp.startAnimation(fabOpen);
}
isFabOpen = !isFabOpen;
facebook.setClickable(isFabOpen);
twitter.setClickable(isFabOpen);
signUp.setClickable(isFabOpen);
}
Related
I am using this tool to get a toggle button behavior, this is the library:
https://github.com/ceryle/SegmentedButton
I want the left and right buttons to have different colors when selected. When I change the color programmatically, it works fine except from inside the listener, any hin on why this would happen?
SegmentedButtonGroup toggle = dialogView.findViewById(R.id.my_toggle);
toggle.setSelectorColor(activity.getResources().getColor(R.color.green));
toggle.setRippleColor(activity.getResources().getColor(R.color.green));
toggle.setOnPositionChanged(new SegmentedButtonGroup.OnPositionChanged() {
#Override
public void onPositionChanged(int position) {
SegmentedButtonGroup toggle = dialogView.findViewById(R.id.my_toggle);
toggle.setSelectorColor(activity.getResources().getColor(R.color.red));
toggle.setRippleColor(activity.getResources().getColor(R.color.red));
}
});
I am also open to other implementations of this functionality, I am having a hard time with this...
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!
I want to disable the navigation arrow in cal droid or else i want to reduce the size of navigation arrow in caldroid. Anyone give solution for this problem. If i give the
dialogCaldroidFragment.setShowNavigationArrows(false);
means the navigation arrow does not hide.
This is work for me
#Override
public void onCaldroidViewCreated() {
if (caldroidFragment.getLeftArrowButton() != null) {
caldroidFragment.setShowNavigationArrows(false);
}
}
I am using AndroidSlidingUpPanel on my project . I want to disable sliding on specific condition . So that only top part is visible , and dragging is disabled .
if(condition){
mSlidingLayout.setEnabled(false);
mSlidingLayout.setClickable(false);
}
if the above code doesn't work then try like
if(condition){
runOnUiThread(new Runnable() {
#Override
public void run() {
mSlidingLayout.setEnabled(false);
mSlidingLayout.setClickable(false);
}
});
}
You can use
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
to lock your DrawerLayout so it won't be able to open with gestures. And unlock it with:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
I have a problem using Clans FloatingActionButton. I need to add a transparent layer that blocks the parent layer. The effect that I need is similar to Google Inbox.
So in my example I have this sequence:
1) Click item 3
2) Click on fab
3) When I click over transparent layer, the item from ListView is clicked.
I try to block the click event transparent layer using:
final FloatingActionMenu menu1 = (FloatingActionMenu) findViewById(R.id.menu1);
menu1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
menu1.close(true);
}
});
So with this code, when I click transparent layer the fab menu is closed (this is ok), but the same click listener blocking the click event over listView.
I have tried different ways to solve this problem but the only way I found was to resize the background programmatically . This is not a good solution because the effect is not good.
In a few hours I'll upload a demo and source code to github , but even as hope someone can help me with some idea. Thank You
EDITED
Here is the LINK to my repo.
Here is the LINK to download this apk
Here is the LINK to video demo
I have download your project from Github and tried the code myself and have solved the issue.
It is working perfectly for me as demonstrated in the Inbox by Google app. You just need to change a very small portion of your code.
menu1.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
#Override
public void onMenuToggle(boolean opened) {
if (opened) {
menu1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
menu1.close(true);
menu1.setClickable(false);
}
});
} else {
Toast.makeText(getApplicationContext(), "Close", Toast.LENGTH_SHORT).show();
}
}
});
Hope I could help you.