I'm developing a new cross-platform application with Xamarin 4.0 and I want change layouts to right to left direction.
I want shell items and flyout menu in right of screen. I tried this code in Shell tag. But it didn't work.
FlowDirection = "RightToLeft"
What should I do?
Thanks.
Unfortunately, it should be the limit of Shell Flyout .
FlowDirection:Just can modify the direction of subview's content, not the parent layout of it.
After testing in official sample Xamarin.Forms - Xaminals , setting FlowDirection = "RightToLeft" can not changing Flyout from left of screen to right of screen.
Note: If have other solutions to solve the direction of parent layout, will update here.
in main activity inside OnCreate method: Make it look like that
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
LoadApplication(new App());
}
Related
Summary
I would like to have more control over the Text rendering on a Button in Xamarin.Forms, so I am using a Grid which contains a Label and Button object. This gives me more control over the text, but it has the side effect of the Label being moved behind the Button when the Button is clicked.
Why does this happen? Shouldn't the ordering of UI be determined by the order in which the children are added to the Grid's Children?
Details
I have created the following code to test the problem in isolation:
// The grid can be added directly to a page
var grid = new Grid();
grid.Margin = new Thickness(100, 100);
grid.WidthRequest = 200;
grid.HeightRequest = 200;
var button = new Button();
button.WidthRequest = 80;
button.HorizontalOptions = LayoutOptions.Start;
button.VerticalOptions = LayoutOptions.Fill;
grid.Children.Add(button);
var label = new Label();
label.Text = "This is some text";
label.VerticalOptions = LayoutOptions.Fill;
label.InputTransparent = true;
grid.Children.Add(label);
The button is sized so that it only overlaps part of the text so that it is clear that the button moves in front of the Label.
Before tapping on the button, this is how the layout appears:
After tapping, the button moves in front of the label as shown in the following image:
I could make the Text have a tap gesture, but then the button wouldn't play its native effect when touched, so I'd like to keep that functionality by clicking on the button.
Is there a way to keep the label in front of the button after a click?
Edit
This has been tested on a Motorola Moto G7 running Android 10 and on an emulator running Android version 9.
Note that on the Android hardware the label remains behind the button permanently. On the emulator the label moves behind the button when the button is pushed, but then re-appears on top after the button is released.
I had done a demo and reappeared the problem. The issue will happend because of the fast renderers. Add the code 'Forms.SetFlags("UseLegacyRenderers");' to your MainActivity class before calling Forms.Init. Such as
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Forms.SetFlags("UseLegacyRenderers");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
In my Xamarin project I have a listview with a search box on the bottom. When I go to type in a search value the virtual keyboard overlaps the search box?
I tried to use Content.layout but I can't match the keyboard and search together Is there a way to fix this do I use a popup control?
void InputFocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,-360, Content.Bounds.Width, Content.Bounds.Height));
}
void InputUnfocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,0, Content.Bounds.Width, Content.Bounds.Height));
}
For ios , you can use this plugin, add to your ios project.
https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/KeyboardOverlap
For android, try to add the following code in App.xaml, new App()
Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
If you still have this issue, please provide mode code here, I will try to reproduce your issue at my side.
How to move search icon of search bar at right hand side in xamarin forms.
I am looking for android and IOS.
For Android I used SearchBarRenderer With below code which does not worked
Anyone know how to do it?Please help.
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
Control.LayoutParameters=(new ActionBar.LayoutParams(GravityFlags.Right));
}
In android, with a custom renderer, you can use the following code to place the search icon at the right side of your search bar:
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var searchView = base.Control as SearchView;
//Get the Id for your search icon
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
ViewGroup linearLayoutSearchView = (ViewGroup)searchViewIcon.Parent;
searchViewIcon.SetAdjustViewBounds(true);
//Remove the search icon from the view group and add it once again to place it at the end of the view group elements
linearLayoutSearchView.RemoveView(searchViewIcon);
linearLayoutSearchView.AddView(searchViewIcon);
}
}
In the above implementation, I simply removed the search icon from the search bar view group and then added it again to the same view group. This placed the normally first child to the last child, thus placing the search icon at the end.
I want to have a TreeView that has all of its children permanently expanded, and I don't want the user to be able to expand or collapse any of the children.
To do this I've found that I need to do the following:
Remove icon with CSS (Done)
Change expand and collapse image TreeView JavaFX 2.2
[edit] Above link should be used to change image; to remove completely, use this solution: https://stackoverflow.com/a/27831191/4430591
Remove double click functionality (Done)
Disable TreeItem's default expand/collapse on double click JavaFX 2.2
[edit] Remove ability to collapse / expand using keyboard arrrow keys (Done)
Given in José Pereda's solution below ( https://stackoverflow.com/a/27831085/4430591 )
[edit] Remove ability to right click for a ContextMenu (Done)
Given in José Pereda's solution below ( https://stackoverflow.com/a/27831085/4430591 )
Remove icon's clickablity (How do I do this?)
[edit] solution: https://stackoverflow.com/a/27831191/4430591
Even though the icon is no longer visible, it's still clickable. I don't see any way of filtering this; I only see ways to be able to respond to it after the fact.
Also, if I'm missing anything else that I need to do to ensure this functionality, please let me know.
I feel quite silly. I think this was mostly just a matter of not knowing what that darn arrow was called. Apparently it's a disclosureNode? Maybe that's common knowledge.
In the custom defined TreeCell, all I did was add this line in the updateItem method:
setDisclosureNode(null);
The solution to avoid modifying the skin or the default behavior is more simple if we trap the clicks before they are dispatched, and consume the right ones.
For that we can use an EventDispatcher, to filter both the mouse pressed and the right click over the arrows, which are StackPane nodes:
class CellEventDispatcher implements EventDispatcher {
private final EventDispatcher original;
public CellEventDispatcher(EventDispatcher original) {
this.original = original;
}
#Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event.getEventType().equals(MouseEvent.MOUSE_PRESSED) ||
event.getEventType().equals(ContextMenuEvent.ANY)){
event.consume();
}
if(event instanceof KeyEvent && event.getEventType().equals(KeyEvent.KEY_PRESSED)){
if((((KeyEvent)event).getCode().equals(KeyCode.LEFT) ||
((KeyEvent)event).getCode().equals(KeyCode.RIGHT))){
event.consume();
}
}
return original.dispatchEvent(event, tail);
}
}
Now we apply our custom dispatcher to the tree view:
#Override
public void start(Stage primaryStage) {
TreeView<String> tree = new TreeView<>();
...
EventDispatcher treeOriginal = tree.getEventDispatcher();
tree.setEventDispatcher(new CellEventDispatcher(treeOriginal));
Scene scene = new Scene(tree);
primaryStage.setScene(scene);
primaryStage.show();
}
This will consume any click (left or right) over the arrows on the tree.
EDIT
Added to the event dispatcher class the case where the user uses the keyboard to traverse the tree view, consuming the collapse/expand events with arrow LEFT or RIGHT.
In Android app, I am using a menubar with tabs attached to it. And each tab has a fragment.
I am trying to set visibility of components (like button) in a fragment to invisible at runtime. But it is not taking effect.
What am I missing?
Main activity class calls a method in Fragment class to set visibility of the button.
But it is not taking effect.
In fragment class,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fm_hd_fragment, container, false);
multicastUp = (Button) view.findViewById(R.id.FmHdMulticastUp);
multicastDown = (Button) view.findViewById(R.id.FmHdMulticastDown);
multicastDisplay = (TextView)view.findViewById(R.id.FmHdCurrentMulticast);
.
.
.
}
public static void showcontrol(){
multicastDisplay.setVisibility(View.VISIBLE);
multicastDown.setVisibility(View.VISIBLE);
multicastUp.setVisibility(View.VISIBLE);
}
In class that wants to update this fragment
FragmentWrapper.showcontrol();
Figured out the issue...
I was trying to update activity from Service directly.
When I use intents from service to update Activity, the UI update works fine.