Is it possible to add some Views above and between the rows in the RowsSupportFragment?
It is possible to add any view above the rows by adding view to parent FrameLayout of VerticalGridView in onViewCreated method. To give space for this view, set proper value for verticalGridView.windowAlignmentOffsetPercent:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
(view.parent as? FrameLayout)?.run {
val myView = LayoutInflater.from(context).inflate(R.layout.my_view_to_add, this, false)
addView(myView)
}
verticalGridView?.let {
it.windowAlignmentOffsetPercent = 30.0f
}
}
This added view is static and won't scroll out when focus goes down.
Between rows it seems there is no way to add anything but ItemDecorator, because VerticalGridView is a descendant of RecyclerView
Related
Consider a textView, how to detect the parent of textView using condition or some logic?
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
TextView text=new TextView(Context);
}
Answer the question as per my understanding:
If you are adding and removing a control a lot of times to get the View's parent you can use the parent property in your case:
text.Parent;
Note that this will be null if there is no parent.
So before using this parent in any way, I would suggest you null check it.
if(text.Parent!=null)
ViewGroup parent = (ViewGroup) textView.getParent();
If parent is null, it is not added to the paren.
You may detect a view as parent using text.Parent, so the code is like this:
TextView text = new TextView(this);
text.Text = "Text";
IViewParent layout = text.Parent;
if (layout == layout2) //To detect whether it is added to parent or not.
{
text.Text = "I am added to layout2";
Console.WriteLine("layout2 is the parent of text");
}
else {
layout2.AddView(text);
}
I have a TableView that is in a descendent controller of a TabViewController. The TableView has items coming from an API. There is also a create new TableItem form/controller which once it has been submitted I need it to present the ViewController with the table view, with an updated list of items from the API.
var storyBoard = this.Storyboard;
var viewController = (TabBarController)storyBoard.InstantiateViewController("TabBarController");
var tabs = viewController.ChildViewControllers;
viewController.SelectedViewController = tabs[1];
PresentViewController(viewController, true, null);
This works as expected in terms of presenting the correct view. But until I force a reload like so:
async Task RefreshAsync()
{
if (_useRefreshControl)
_refreshControl.BeginRefreshing();
if (_useRefreshControl)
_refreshControl.EndRefreshing();
BookingsTableView.ReloadData();
}
The view just displays the same items in the TableView when on the load of the page it should be querying the API and loading the list:
_bookings = await _apiService.GetBookingsForCustomer(model.CustomerEmail);
_dataSource = new BookingTableSource(_bookings, this);
BookingsTableView.Source = _dataSource;
BookingsTableView.ReloadData();
Should also note this app is only a simple proof of concept.. But how can I get it to Instantiate my TableViewController whilst still Presenting the TabBarController?
Thanks,
Danny
Solved this, just dismissed the ViewController with the booking form and called my refresh method in the ViewDidAppear override in the ViewController with the bookings TableView:
public override void ViewDidAppear(bool animated)
{
RefreshData();
}
I have a list view that I am popping up in Xamarin forms, that I want to hide if someone taps outside of the box. I have a tap gesture recognizer on the parent layout for the list view that handles that. In Android, it all works good. If I click off, it closes, but if I click on an element in the list view, it properly selects it. In iOS, the opposite happens. The gesture handler on the layout fires first and closes the list view without properly selecting the item.
So my question, is there a way to change the order on how the events are fired? If not, is there a better alternative to how I'm trying to accomplish this? Thanks!
If you are using ListView.ItemSelected or ListView.ItemTapped then I ran into the exact same issue the other day. The fix for me was to not use either of those and instead attach a TapGestureRecognizer to the ViewCell that is within the ListView. I also added an IsSelected property to the object that the ViewCell is being bound to so that I could change the background color of the item once it has been clicked.
public class SomePage : ContentPage {
private SomeModel _selectedModel; //It would be best to put this into your ViewModel
...
public SomePage() {
ListView list = new ListView {
ItemTemplate = new DataTemplate(() => {
ViewCell cell = new ViewCell {
View = new ContentView()
};
cell.View.GestureRecognizers.Add(new TapGestureRecognizer {
Command = new Command(() => {
if(_selectedModel != null) { _selectedModel.IsSelected = false; }
SomeModel model = (SomeModel)cell.BindingContext;
model.IsSelected = true;
_selectedModel = model;
})
}
return cell;
}
}
}
}
I need to add a custom tab item into my TabbedPage. That shouldn't be a page but an overlay view. It is "More" item for the bottom menu opening a more items menu over the currently shown page.
So far I found the following solution:
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
if (this.isInitialized)
{
if (CurrentPage.Title == "More")
{
CurrentPage = this.lastSelectedPage;
}
}
this.lastSelectedPage = CurrentPage;
}
It's enough to prevent opening the corresponding fake page. After this I need to show an overlay view and have no item how to do it from the tabbed page.
Another solution I'm working out now is to write a custom renderer for my tabbed page and manage all the custom work there. The question in this case is how to show my custom view over the existing content. I tried AddView (iOS) in the renderer but getting runtime exception.
public override void ItemSelected(UITabBar tabbar, UITabBarItem item)
{
base.ItemSelected(tabbar, item);
var view = new UILabel()
{
Text = "Test"
};
View.Add(view);
}
Wanting to achieve a consistent look for my Xamarin Forms app, I need to know how to change the font for the tabbed page tab bar icons. Using UITabBarItem.Appearance as the iOS API would suggest does not appear to have any effect. What's necessary to do this?
U need to write a custom renderer like this one , take a clue from below code ! it has what u r seeking
[assembly: ExportRenderer(typeof(ExtendedTabbedPage), typeof(TabbedPageCustom))]
namespace App.iOS
{
public class TabbedPageCustom : TabbedRenderer
{
public TabbedPageCustom ()
{
TabBar.TintColor = UIKit.UIColor.White;
TabBar.BarTintColor = UIKit.UIColor.White;
TabBar.BackgroundColor = UIKit.UIColor.Red;
}
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged (e);
// Set Text Font for unselected tab states
UITextAttributes normalTextAttributes = new UITextAttributes();
normalTextAttributes.Font = UIFont.FromName("ChalkboardSE-Light", 20.0F); // unselected
normalTextAttributes.TextColor = UIKit.UIColor.Blue;
UITabBarItem.Appearance.SetTitleTextAttributes(normalTextAttributes, UIControlState.Normal);
}
public override UIViewController SelectedViewController {
get {
UITextAttributes selectedTextAttributes = new UITextAttributes();
selectedTextAttributes.Font = UIFont.FromName("ChalkboardSE-Bold", 20.0F); // SELECTED
if (base.SelectedViewController != null)
{
base.SelectedViewController.TabBarItem.SetTitleTextAttributes(selectedTextAttributes, UIControlState.Normal);
}
return base.SelectedViewController;
}
set {
base.SelectedViewController = value;
foreach (UIViewController viewController in base.ViewControllers)
{
UITextAttributes normalTextAttributes = new UITextAttributes();
normalTextAttributes.Font = UIFont.FromName("ChalkboardSE-Light", 20.0F); // unselected
normalTextAttributes.TextColor = UIKit.UIColor.Blue;
viewController.TabBarItem.SetTitleTextAttributes(normalTextAttributes, UIControlState.Normal);
}
}
}
}
}
This was a particularly interesting problem. I tried:
UITabBarItem.Appearance
Using the UITabBarItem.Appearance.SetTitleTextAttributes method to update the UITextAttribute to my font (size 9.0f) for UIControlState.Normal. This didn't appear to make any difference.
UINavigationBar.Appearance
I found out that setting UINavigationBar.Appearance.SetTitleTextAttributes would update both the UINavigationBar text appearance as well as the UITabBarItem text appearance.
Which was a problem because the tabbed page item font size was far too large.
Customizing the TabbedRenderer
Inspired by a sample I saw somewhere, I subclassed TabbedRenderer in the iOS project.
I tried overriding the settor for TabbedRenderer.SelectedViewController property and loop through the ViewControllers property to set their items. The icons would display with the standard font, but once the user changed the tab they would all update to the desired font. Almost there!
I then tried overriding AddChildViewController and updating that controller's TabBarItem after it was added which ended up having no effect. The TabBarItem for the added page was being updated at some point after the controller was added.
Eventually I found out that overriding ViewWillAppear and setting the appearance for all the tab bar items at that time seemed to do the job I desired.
I've included a sample in this gist.