xamsvg SvgImageView xamarin android no display - xamarin

I try to test the XamSVG for android but no display and in debug the error is:
Failed to set EGL_SWAP_BEHAVIOR on surface 0xdb72a380,
error=EGL_SUCCESS.
How to solve this ?
I added the .svg file in res/raw/home.svg
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<xamsvg.SvgImageView
local:svg="#raw/home"
android:layout_width="wrap_content"
android:layout_height="50dp" />
</RelativeLayout>

Related

Show BottomNavigationView when stop scrolling

I use attribute app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" to hide BottomNavigationView when I'm scrolling down. It works. When I scroll up, BNV is showed again. Also works. But when I finished scrolling down (BNV is hidden) I want to see BNV without scrolling up. Is it possible?
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2AB670"
tools:context=".presentation.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/bottom_navigation_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/app_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green_01"
app:itemBackground="#drawable/bottom_navigation_selector"
app:itemIconTint="#color/white"
app:itemTextAppearanceActive="#style/ItemTextAppearanceActive"
app:itemTextColor="#color/white"
app:labelVisibilityMode="labeled"
app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior"
android:layout_gravity="bottom"
app:menu="#menu/bottom_navigation_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Android Navigation Component: How do I style toolbar based on navigation graph

I have the following nav_graph.xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_graph"
app:startDestination="#id/actualFragment">
<fragment
android:id="#+id/actualFragment"
android:name="com.online.view.ui.ActualFragment"
android:label="Актуальное"
tools:layout="#layout/fragment_actual" >
<action
android:id="#+id/action_actualFragment_to_actualEventFragment"
app:destination="#id/actualEventFragment"
app:enterAnim="#anim/nav_default_pop_enter_anim"
app:exitAnim="#anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="#+id/actualEventFragment"
android:name="com.online.view.ui.detail.ActualEventFragment"
android:label="Актуальное"
tools:layout="#layout/actual_event_fragment" />
</navigation>
and I have MainActivity with the following layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent" android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:background="#color/white"
android:paddingLeft="8dp"
app:contentInsetStart="8dp"
app:contentInsetStartWithNavigation="0dp"
app:titleTextAppearance="#style/TabTitles"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="#style/ToolbarStyle"
/>
<fragment
android:id="#+id/content"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="#+id/bottom_tabs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.587"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:navGraph="#navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_tabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="#drawable/bottom_nav_colors"
app:itemTextAppearanceActive="#style/bottomBarTextSelected"
app:itemTextAppearanceInactive="#style/bottomBarText"
app:itemIconTint="#drawable/bottom_nav_colors"
android:alpha="1.0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/tabs_navigation"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Now I want to have different styling for activity toolbar when top level fragment is loaded and when its child is loaded (showing back arrow in toolbar).
QUESTION: How can I achieve this different styling for toolbar (appbar) if I use Android Navigation Component and I navigate from root fragment to child fragment using the following code:
Bundle bundle = new Bundle();
bundle.putString("id", ei.id);
MainActivity)context).getNavController().navigate(R.id.action_actualFragment_to_actualEventFragment, bundle);
NavigationUI uses an AppBarConfiguration object to manage the behavior of the Navigation button. The Navigation button’s behavior changes depending on whether the user is at a top-level destination. Have a look at their documentation Update UI components with NavigationUI

Dynamically load xml control and share UI control

I am new to xamarin. Is it possible to load a shared UI control in an xml file, if yes, how? I am open to better idea.
Below is a static loading via include, where parent.axml statically load child.xml.
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
parent.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parent_layout"
android:layout_below="#id/child">
<TextView
android:id="#+id/parent_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to go to the moon!"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
Child.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/child_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You made it!"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
The idea is that it can achieve share of UI controls. In this case, parent.axml loads child.xml into its place holder based on condition.
You can use LayoutInflater to inflate layouts and auto-attach them to the parent (or not):
var linearLayout = LayoutInflater.Inflate(Resource.Layout.Child, parent, true);
var textView = linearLayout.FindViewById<TextView>(Resource.Id.child_text);
textView.Text = "Inflated and attached to Parent";
Also depending upon your use-case, using a self-contained Fragment and adding that to your "parent" might be better a better solution.

Xamarin Bottom Bar Gets Lost

I have a listview, a toolbar and a bottom nav bar. Toolbar is aligned to top while nav bar is aligned to bottom. Its working well unless i add items to listview. After adding 5 items, the bottom bar disappears. Cant i align the bot bar like the toolbar so it just stays still ?
Activity's axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/listv_sepet" />
<include
android:id="#+id/toolbar_bottom"
layout="#layout/toolbar_bot"
android:layout_alignParentBottom="true"/>
</LinearLayout>
</RelativeLayout>
Bottom Toolbar axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
Thanks in the advance.
The problem is that you wrap the height of the ListView and don't tell it to be above the bottom Toolbar.
This can easily be fixed by:
un-nesting your layout as it is not really necessary in this case to do any nesting.
tell the ListView to be below the top Toolbar and above the bottom Toolbar
So something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
android:layout_alignParentTop="true"
layout="#layout/toolbar" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:layout_above="#+id/toolbar_bottom"
android:id="#+id/listv_sepet" />
<include
android:id="#+id/toolbar_bottom"
layout="#layout/toolbar_bot"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
That should fix it.
Rather than using an include in your layout you can set the footer (and header) in code when binding to the listview by using the AddHeaderView and AddFooterView methods
For example:
listView = view.FindViewById<ListView>(Resource.Id.mylistView);
View headerView = View.Inflate(Activity, Resource.Layout.ListHeader, null);
listView.AddHeaderView(headerView);

MvxGridView - crash when item template is set

I tried to use Mvx.MvxGridView but it crash when I set MvxItemTemplate with debug output message:
Could not find method android.widget.GridView.<init>, referenced from method cirrious.mvvmcross.binding.droid.views.MvxGridView.<init>
Crashing code:
<Mvx.MvxGridView
android:id="#+id/GridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource SomeSource"
local:MvxItemTemplate="#layout/itemtemplatepath"/>
Item template:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/MyApp.Droid">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="top|center"
local:MvxBind="Text Member.FirstName"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
If MvxItemTemplate isn't set - then MvxGridView is rendered with default ItemTemplate (text with full class name). Any suggestions?
Ok my fault - it works but LinearLayout (every defined View) should have explicitly set "android:layout_width" and "android:layout_height".

Resources