FloatingActionButtonSpeedDial
FloatingActionButtonSpeedDial copied to clipboard
Orientation change issue
Orientation issue
Hi
I started using this speed dial and I'm running into an issue with orientation
In protrait mode I load items and set lables. in landscape mode I do noty set the labels
when the activity detects an orientation change I clear the itmes and reload them with labels on or off based on the orientation. I also set the oriienation of the speed dial itsel and reopen it if it was open before the orientation change
Starting in protrait mode: all is good. FABs are displayed vertivcally with labels. Change to landscape mode: all is good. FABS displayed horizontally without labels Back to protrait: Problem: FABS are displayed vertically but the labels are missing.
Is there somethins I'm missing?
Thanks for the help
Here is the orientation change code:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
boolean open = mSpeedDialView.isOpen();
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setFabItems(newConfig.orientation);
mSpeedDialView.setOrientation(LinearLayout.VERTICAL);
} else {
setFabItems(newConfig.orientation);
mSpeedDialView.setOrientation(LinearLayout.HORIZONTAL);
}
mSpeedDialView.requestLayout();
if (open) {
mSpeedDialView.open();
}
}
private void setFabItems(int orientation) {
SpeedDialActionItem item1 = null;
SpeedDialActionItem item2 = null;
mSpeedDialView.clearActionItems();
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
item1 = new SpeedDialActionItem.Builder(R.id.fab_item1, R.drawable.ic_fab_item1)
.setLabel(R.string.fab_item1)
.setFabBackgroundColor(getResources().getColor(R.color.colorPrimary, null))
.setLabelBackgroundColor(getResources().getColor(R.color.colorPrimaryDark, null))
.setLabelColor(getResources().getColor(R.color.grey_18, null))
.create();
item2 = new SpeedDialActionItem.Builder(R.id.fab_item2, R.drawable.ic_fab_item2)
.setLabel(R.string.fab_item2)
.setFabBackgroundColor(getResources().getColor(R.color.colorPrimary, null))
.setLabelBackgroundColor(getResources().getColor(R.color.colorPrimaryDark, null))
.setLabelColor(getResources().getColor(R.color.grey_18, null))
.create();
} else {
item1 = new SpeedDialActionItem.Builder(R.id.fab_item1, R.drawable.ic_fab_item1)
.setLabel(R.string.fab_item1)
.setFabBackgroundColor(getResources().getColor(R.color.colorPrimary, null))
.create();
item2 = new SpeedDialActionItem.Builder(R.id.fab_item2, R.drawable.ic_fab_item2)
.setLabel(R.string.fab_item2)
.setFabBackgroundColor(getResources().getColor(R.color.colorPrimary, null))
.create();
}
mSpeedDialView.addActionItem(item1);
mSpeedDialView.addActionItem(item2);
}
This issue has been automatically marked as stale because it has not had activity in the last 60 days.
Hi! There is no need to manually not to set labels.
You can try this code and the labels will be automatically hidden in landscape mode.
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
speedDialView.setOrientation(LinearLayout.VERTICAL);
speedDialView.setExpansionMode(SpeedDialView.ExpansionMode.TOP);
} else {
speedDialView.setOrientation(LinearLayout.HORIZONTAL);
speedDialView.setExpansionMode(SpeedDialView.ExpansionMode.LEFT);
}
}