I added an RoutingEffect in Xamarin Form project and PlatformEffect in my Xamarin.iOS project. It will add effect to Stacklayout. The Stacklayout in this demo is a custom navigation bar. The below of navigation bar is a scrollview has many cells (label, entry, picker).
I implemented in Android is OK.
But in iOS has problem: Shadow effect cannot overlays some controls, such as: Entry, Editor, Picker. Could you share me how to fix it?
This is code in Xamarin.iOS project.
public class DropShadowEffect : PlatformEffect
{
protected override void OnAttached()
{
try
{
var effect = (myDemo.UIControls.DropShadowEffect)Element.Effects.FirstOrDefault(e => e is myDemo.UIControls.DropShadowEffect);
if (effect != null)
{
Container.Layer.CornerRadius = effect.Radius;
Container.Layer.ShadowColor = UIColor.Red.CGColor;// effect.Color.ToCGColor();
Container.Layer.ShadowOffset = new CGSize(effect.DistanceX, effect.DistanceY);
Container.Layer.ShadowOpacity = 0.8f;
Container.Layer.ShadowRadius = 2f;
Container.Layer.ShouldRasterize = true;
Container.Layer.MasksToBounds = false;
}
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: {0}", ex.Message);
}
}
*Shadow effect overly Label is OK
*Shadow effect cannot overlay either Picker or Entry
Cause:
Actually, such as Label will still overlay the shadow.But it doesn't seem obvious.If you set the background of label (such as red ),you will see the overlay.
Solution:
You can set the BackgroundColor of the Picker and Entry in the custom renderer to let the alpha as 0.
For example in EntryRenderer
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BackgroundColor = new UIColor(1,1,1,0);//The last parameter sets the alpha of backgound as transparent
Control.Layer.MasksToBounds = true;
Control.Layer.CornerRadius = xxx; //set the rounded corner
Control.Layer.BorderColor = UIColor.xxx.CGColor;
Control.Layer.BorderWidth = xxx;
}
}
When I focus that Editor, a keyboard overlaps Editor and Button. I know, there is a solution: putting elements inside ScrollView, but this solution makes huge problems with scrolling ListView inside ScrollView. What should I do, to make it work properly?
Layout:
red - ScrollView,
green - ListView,
blue - StackLayout with Editor and Button.
Here is the video how this works:
https://streamable.com/wvd3h
Solution #2 is to use Xamarin.Forms.Plugins - KeyboardOverlap, but this plugin has a problem with tab bar on TabbedPage
Rather than using a scrollview, you could create a custom iOS renderer that shifts your view up (using the margin) when the keyboard is active.
An example of this can be seen here:
https://github.com/rdelrosario/ChatUIXForms/blob/master/ChatUIXForms.iOS/Renderers/ChatEntryRenderer.cs
Relevant code:
void RegisterForKeyboardNotifications()
{
if (_keyboardShowObserver == null)
_keyboardShowObserver = UIKeyboard.Notifications.ObserveWillShow(OnKeyboardShow);
if (_keyboardHideObserver == null)
_keyboardHideObserver = UIKeyboard.Notifications.ObserveWillHide(OnKeyboardHide);
}
void OnKeyboardShow(object sender, UIKeyboardEventArgs args)
{
NSValue result = (NSValue)args.Notification.UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
CGSize keyboardSize = result.RectangleFValue.Size;
if (Element != null)
{
Element.Margin = new Thickness(0, 0, 0, keyboardSize.Height); //push the entry up to keyboard height when keyboard is activated
}
}
void OnKeyboardHide(object sender, UIKeyboardEventArgs args)
{
if (Element != null)
{
Element.Margin = new Thickness(0); //set the margins to zero when keyboard is dismissed
}
}
void UnregisterForKeyboardNotifications()
{
if (_keyboardShowObserver != null)
{
_keyboardShowObserver.Dispose();
_keyboardShowObserver = null;
}
if (_keyboardHideObserver != null)
{
_keyboardHideObserver.Dispose();
_keyboardHideObserver = null;
}
}
On Android, it's likely not an issue, but if it is, you could try
android:Application.WindowSoftInputModeAdjust="Resize"
I'm using a UITabbarViewController in a relatively simple way. My issue only appears on iPad devices of iOS11 version. It's not visible on iOS10 or iPhone.
If you look at the screenshot, you can see that the background color of the tab is not aligned. Actually, it is aligned, it's the tabbar itself that is not taking the full width. So the background color is overlapping towards the central button because it's not using the space on the far left and far right.
I'm assuming that the tabbar is broken (and not my background colors, which are drawn manually) because the edges of the outsides tabs are not clickable, and yet the item positioning is set to be filling the width of the screen :
TabBar.ItemPositioning = UITabBarItemPositioning.Fill;
The items sizes are wrong if you consider the tabbar fullscreen, but they are if you consider the "reduced" version. So i'm pretty sure it's all good there, as long as the tabbar decides to take the full width of the screen, the buttons and background color will then have the correct measurements.
I've tried using View.LayoutIfNeeded() and SetNeedsLayout() to force a redraw, but to no avail.
I'm not sure why it's even behaving like so, and since it's the default behaviour of the OS and I haven't done anything particular, I'm not certain of what can even be tried.
Here's some relevant code :
MainTabbarController tabController = (MainTabbarController)Window.RootViewController;
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
ConfigureTabbar();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
UIViewController[] tabs = //Create the VCs in the most basic way
SetViewControllers(tabs, false);
}
protected virtual void ConfigureTabbar()
{
TabBar.Translucent = false;
TabBar.ItemPositioning = UITabBarItemPositioning.Fill;
TabBar.ItemSpacing = 0;
//View.LayoutIfNeeded();
float tabbarItemWidth = (float)Math.Ceiling(View.Bounds.Width / TabBar.Items.Length) + 1; //+ 1 to avoid the right pixel that was not filled on the right tab. Strange behaviour...
TabBar.ItemWidth = tabbarItemWidth;
//var version = NSProcessInfo.ProcessInfo.OperatingSystemVersion;
NSOperatingSystemVersion ios11 = new NSOperatingSystemVersion(11, 0, 0);
if (NSProcessInfo.ProcessInfo.IsOperatingSystemAtLeastVersion(ios11))
{
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
TabBar.SelectionIndicatorImage = _viewModel.Styles.Colors.ActiveTabColor.ToNative().ToImage(new CGRect(0, -View.SafeAreaInsets.Bottom, tabbarItemWidth, TabBar.Frame.Height));
}
else
{
TabBar.SelectionIndicatorImage = _viewModel.Styles.Colors.ActiveTabColor.ToNative().ToImage(new CGRect(0, -View.SafeAreaInsets.Bottom, tabbarItemWidth, TabBar.Frame.Height));
}
}
else
{
TabBar.SelectionIndicatorImage = _viewModel.Styles.Colors.ActiveTabColor.ToNative().ToImage(new CGSize(tabbarItemWidth, TabBar.Frame.Height));
}
UITextAttributes attrs = new UITextAttributes();
attrs.Font = _viewModel.Styles.Fonts.ExtraSmall.ToNative();
attrs.TextColor = _viewModel.Styles.Colors.ActionText.ToNative();
UITabBarItem.Appearance.SetTitleTextAttributes(attrs, UIControlState.Normal);
for (int i = 0; i < TabBar.Items.Length; i++)
{
UITabBarItem item = TabBar.Items[i];
item.Title = _viewModel.Titles[i];
item.TitlePositionAdjustment = new UIOffset(0, -4);
item.ImageInsets = new UIEdgeInsets(-2, 0, 2, 0);
}
//View.LayoutIfNeeded();
}
I have a Settings View with a styled AppBar and when I open a full screen dialog from that View, the AppBar styling follows the global swatch specified.
THEN, when I close the dialog box, the Settings View AppBar retains the dialog styling (it should have a white background, but it's green which is the swatch that is specified for the application).
Further Clarification:
The View is a page for Settings and then when you click each setting a dialog pops up with the content set to StackPanes that contain information for that specific setting.
I have tried to add a method that stylizes the AppBar on Dialog close, hide, and hidden event handlers:
public void initView(SettingView viewType) {
View pane = null;
try {
switch (viewType) {
case PASSWORD_CHANGE:
pane = getPasswordPane();
break;
case PROFILE_CHANGE:
pane = getProfilePane();
break;
case BANK_CHANGE:
pane = getBankPane();
break;
case NOTIFICATION_CHANGE:
pane = getNotificationPane();
break;
}
} catch (IOException e) {
System.out.println("IOException: " + e);
}
//this.settingsContainer = new Dialog(true);
this.settingsContainer.setContent(pane);
MobileApplication.getInstance().removeLayerFactory("$$$DropdownButtonSkin$$$");
Platform.runLater(new Runnable() {
#Override
public void run() { //None of these change the appbar styling
settingsContainer.setOnShowing(e -> { setAppBar("Settings");});
settingsContainer.setOnShown(e -> { setAppBar("Settings");});
settingsContainer.setOnHiding(e -> { setAppBar("Settings");});
settingsContainer.setOnHidden(e -> { setAppBar("Settings");});
//When closing the appbar the color remains to the swatch instead of the customized background
settingsContainer.setOnCloseRequest(e -> { setAppBar("Settings");});
settingsContainer.showAndWait();
}
});
}
public AppBar setAppBar(String name) {
Button menu = MaterialDesignIcon.MENU.button();
menu.setStyle("-fx-text-fill:darkgreen;");
menu.setOnMouseClicked(e -> {
MobileApplication.getInstance().showLayer(Appstar.MENU_LAYER);
});
AppBar appBar = MobileApplication.getInstance().getAppBar();
appBar.clear();
appBar.setNavIcon(menu);
appBar.setTitleText(name);
appBar.setVisible(true);
appBar.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(0), new Insets(0, 0, 0, 0))));
return appBar;
}
Considering that you want the same app-bar color on all views (i.e. white in all the views), the easiest way to solve this is to use CSS.
You can set the color of the AppBar on a full-screen dialog by using the custom style-class for the AppBar on a full-screen dialog i.e. dialog-fullscreen along with the base style-class app-bar. Therefore, you can use something like this:
.app-bar.dialog-fullscreen {
-fx-background-color: green; // OR -primary-swatch-500;
}
For setting the overall app-bar color to white, you can simply use:
.app-bar {
-fx-background-color: white;
}
i wanna know, how to fit screen my tabulation bar on blackberry. because my tab is match with blackberry 9700 but for blackberry 9900, my tab is too small. i wanna my tab is fit to all device scree.
thanks in advance :)
this is the code, i got from other post. sorry:
BottomPanel class
public class BottomPanel extends VerticalFieldManager implements
FieldChangeListener {
Bitmap home_bit = Bitmap.getBitmapResource("home.png");
Bitmap home_bit_hover = Bitmap.getBitmapResource("home_h.png");
Bitmap map_bit = Bitmap.getBitmapResource("map.png");
Bitmap map_bit_hover = Bitmap.getBitmapResource("map_h.png");
Bitmap contact_bit = Bitmap.getBitmapResource("contact.png");
Bitmap contact_bit_hover = Bitmap.getBitmapResource("contact_h.png");
PictureBackgroundButtonField home_pic, map_pic, contact_pic;
HorizontalFieldManager hr;
int current_index = 0;
public BottomPanel(int current_index) {
super(FOCUSABLE);
this.current_index = current_index;
VerticalFieldManager ver = new VerticalFieldManager(USE_ALL_WIDTH
| USE_ALL_HEIGHT) {
protected void sublayout(int width, int height) {
super.sublayout(width, home_bit.getHeight());
setExtent(width, home_bit.getHeight());
}
};
hr = new HorizontalFieldManager(FIELD_HCENTER);
if (current_index == 1) {
home_pic = new PictureBackgroundButtonField(home_bit.getWidth(),
home_bit.getHeight(), Field.NON_FOCUSABLE
| Field.FIELD_VCENTER, home_bit_hover,
home_bit_hover);
} else {
home_pic = new PictureBackgroundButtonField(home_bit.getWidth(),
home_bit.getHeight(),
Field.FOCUSABLE | Field.FIELD_VCENTER, home_bit,
home_bit_hover);
}
home_pic.setChangeListener(this);
hr.add(home_pic);
if (current_index == 2) {
map_pic = new PictureBackgroundButtonField(map_bit.getWidth(),
map_bit.getHeight(), Field.NON_FOCUSABLE
| Field.FIELD_VCENTER, map_bit_hover, map_bit_hover);
} else {
map_pic = new PictureBackgroundButtonField(map_bit.getWidth(),
map_bit.getHeight(), Field.FOCUSABLE | Field.FIELD_VCENTER,
map_bit, map_bit_hover);
}
map_pic.setChangeListener(this);
hr.add(map_pic);
if (current_index == 3) {
contact_pic = new PictureBackgroundButtonField(
contact_bit.getWidth(), contact_bit.getHeight(),
Field.NON_FOCUSABLE | Field.FIELD_VCENTER,
contact_bit_hover, contact_bit_hover);
} else {
contact_pic = new PictureBackgroundButtonField(
contact_bit.getWidth(), contact_bit.getHeight(),
Field.FOCUSABLE | Field.FIELD_VCENTER, contact_bit,
contact_bit_hover);
}
contact_pic.setChangeListener(this);
hr.add(contact_pic);
ver.add(hr);
add(ver);
}
public void fieldChanged(Field field, int context) {
if (field == home_pic) {
LoadingScreen loadingScreen = new LoadingScreen(1);
UiApplication.getUiApplication().popScreen(
UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(loadingScreen);
loadingScreen.createGUI();
} else if (field == map_pic) {
LoadingScreen loadingScreen = new LoadingScreen(2);
UiApplication.getUiApplication().popScreen(
UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(loadingScreen);
loadingScreen.createGUI();
} else if (field == contact_pic) {
LoadingScreen loadingScreen = new LoadingScreen(3);
UiApplication.getUiApplication().popScreen(
UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(loadingScreen);
loadingScreen.createGUI();
}
}
Loading Screen class
public class LoadingScreen extends MainScreen {
private LabelField text;
private LabelField texthasil;
private VerticalFieldManager manager;
int current_index = 0;
BottomPanel bottomPanel;
public LoadingScreen(int current_index) {
this.current_index = current_index;
bottomPanel = new BottomPanel(current_index);
setStatus(bottomPanel);
}
public void createGUI() {
manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
| Manager.VERTICAL_SCROLLBAR);
setStatus(bottomPanel);
}
PictureBackgroundButtonField class
public class PictureBackgroundButtonField extends Field {
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;
private Bitmap _currentPicture;
private Bitmap _onPicture;
private Bitmap _offPicture;
public PictureBackgroundButtonField(int width, int height, long style,
Bitmap picture, Bitmap selectedPic) {
super(style);
_font = getFont();
_label = "";
_labelHeight = height;
_labelWidth = width;
_currentPicture = picture;
_onPicture = selectedPic;
_offPicture = picture;
}
protected void drawFocus(Graphics graphics, boolean on) {
// Do nothing
}
public int getPreferredHeight() {
return _labelHeight;
}
public int getPreferredWidth() {
return _labelWidth;
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
protected void onFocus(int direction) {
_currentPicture = _onPicture;
invalidate();
}
protected void onUnfocus() {
_currentPicture = _offPicture;
invalidate();
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, getPreferredWidth(), getPreferredHeight(),
_currentPicture, 0, 0);
graphics.setFont(_font);
graphics.drawText(
_label,
4,
2,
(int) (getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),
getWidth() - 6);
}
You don't show us what kind of tab bar background you have, and the solution does depend a little on that. If you are happy having a tab bar that is always the same height (in pixels), but just changes width, then you could use something like this.
I create a Manager subclass called TabBarManager. It will span the whole width of your screen, with a fixed height. It can have Field objects added to it like any normal manager. It is intended to have button fields added to it, so that when you click the button field, something happens. Probably, you'd also want the appearance of the button fields to change, depending on which tab is selected. However, it wasn't clear that this question was about that problem, so I didn't show that code. All this code does is give you a Manager to add tab fields to, that will draw a full-width background.
The tab bar fields that you add to this should contain icon images and/or labels, that have transparent backgrounds. For example, a white silhouette icon of a globe, if the tab is a map view. The transparent background shows through to the TabBarManager background.
The technique is to draw (in Photoshop, or whatever) three images. A left, right, and center image. Think of drawing a full tab bar image. Then, crop off the left few pixels, and save as TabBar-left.png. Crop the right few pixels and save as TabBar-right.png, and then crop a few pixels out of the center, and save as TabBar-center.png. Example images are shown below the code:
/**
* A TabBarManager provides a horizontal bar of button fields, that serve as a tab bar
* header or footer, used to select between available subviews in a larger Screen.
*/
private final class TabBarManager extends HorizontalFieldManager {
private int height;
private Bitmap left;
private Bitmap center;
private Bitmap right;
public TabBarManager() {
super(HorizontalFieldManager.NO_VERTICAL_SCROLL); // tab bar itself doesn't scroll
left = Bitmap.getBitmapResource("TabBar-left.png");
right = Bitmap.getBitmapResource("TabBar-right.png");
center = Bitmap.getBitmapResource("TabBar-center.png");
height = left.getHeight();
}
public void sublayout(int width, int h) {
super.sublayout(width, height);
setExtent(width, height); // restrict height to a fixed value
}
public int getPreferredHeight() {
return height;
}
public void paint(Graphics g) {
// draw the background image for the tab bar with two sides and a center section,
// to account for the fact that different devices have different widths
int width = Display.getWidth();
g.drawBitmap(0, 0, left.getWidth(), height, left, 0, 0);
// fill in the center by repeating the center image as many times as needed
int x = left.getWidth();
int centerWidth = center.getWidth();
int leftEdgeOfRightBitmap = width - right.getWidth();
while (x < leftEdgeOfRightBitmap) {
g.drawBitmap(x, 0, centerWidth, height, center, 0, 0);
x += centerWidth;
}
// draw right side
g.drawBitmap(leftEdgeOfRightBitmap, 0, right.getWidth(), height, right, 0, 0);
// use super.paint() to draw the icons/labels on top of our background
super.paint(g);
}
}
Left, center, and right PNGs (must be same height ... width doesn't matter):
, ,
How You Use It
In the code you show, you can either replace your hr variable with an instance of my TabBarManager. Or you can rename my TabBarManager class to BottomPanel, and add the additional code you need to it ... things like the current index, and the field change listener callback.
Limitations
The above implementation will only stretch the tab bar's width. The height is fixed. For a fully stretchable tab bar, you could either mimic a 9-patch image by drawing 9 images (top-left, top-center, top-right, left, center, right, bottom-left, bottom-center, bottom-right). Or use something like this to get 9-patch stretchable images for BlackBerry
References
http://supportforums.blackberry.com/t5/Java-Development/Create-tabbed-view-screens/ta-p/444969