Why can't I interact with any views within my fragments? - xamarin

^.^
I'm very new to xamarin.android and xamarin in general, and I'm finding the layout handling so much more trouble than I expected! I've finally managed to get fragments switching in and out in order to display different pages in my app, but now that that's working, the views/controls/elements such as buttons, scrollable layouts, text input, etc are not accepting input!
By that, I mean when testing, buttons do not recognise me tapping on them, my once-scrollable listview no longer scrolls when I swipe, etc.
This only applies to the views within the fragments, as the navigation drawer and other persistent default app buttons are all still fine.
I've looked for solutions everywhere but can't find anything that helps!
I'd greatly appreciate any advice/assistance, and if you require any additional information please just ask! ^.^
Thanks so much in advance! ^.^ <3
Code:
activity_main.xml:
<androidx.drawerlayout.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/white"
android:id="#id/MainLayout"
android:paddingTop="50dp">
</LinearLayout>
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
One of my fragment layouts (content_main.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_main"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:id="#+id/ClothesList_ListView"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
android:choiceMode="singleChoice"
android:scrollbarSize="40px"/>
</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>

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 - How can i remove extra space at the top of dialogfragment

I have created a dialog fragment in Xamarin. My only issue is that this fragment shows a grey part on it. And i can't figure out what causes the grey part to appear. Do you guys perhaps know the possible cause ?
I'm using this code to display this dialog :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:focusableInTouchMode="true">
<View
android:id="#+id/makedialogfullscreenChooseSoundTrack"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="fill_horizontal"
/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e1effa" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Choose Sound Track"
android:textSize="20dp"
android:textColor="#673ab7"
android:padding="15dp"
android:layout_marginRight="25dp"
/>
<ImageView
android:id="#+id/imgCloseSoundDialog"
android:layout_width="33dp"
android:layout_height="33dp"
android:src="#drawable/close_icon"
android:layout_marginBottom="15.5dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<GridView
android:id="#+id/gvSoundFiles"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:gravity="center"
android:verticalSpacing="5dp"
android:drawSelectorOnTop="true"
android:stretchMode="columnWidth" />
</LinearLayout>
</LinearLayout>
I solved the issue by adding this line in OnCreateView(..) method :
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
by default the DialogFragment comes with a theme with a title bar, to solve this put the code below in the constructor
SetStyle(DialogFragmentStyle.NoTitle, 0);

Upgrading from Android Wear 2.0.0-alpha3 to 2.0.0 release breaks my layouts

After upgrading from 2.0.0-alpha3 to 2.0.0, most of my views looked skewed. This is the XML of the layout I am using:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="oviroa.bestshot.android.StartPlayActivity"
tools:deviceIds="wear"
android:padding="15dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:layout_box="all">
<TextView
android:id="#+id/shot_type"
app:layout_box="all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/forehand"
android:theme="#style/BST.HeaderText"/>
<Button
android:layout_marginTop="30dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="#+id/record"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/swoosh_background"
android:text="#string/record_action"
android:gravity="center_horizontal|bottom"
android:textAlignment="center"
android:paddingBottom="15dp"
android:theme="#style/BST.ButtonWithIcon.Bold" />
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
The button is considerably skewed as you can see in the screenshots below. Iam not doing any manipulations via code.
This is with 2.0.0-alpha3:
And this is with 2.0.0, the final release:
I am testing on LG Urbane 2nd gen LTE.
This was actually a bug fix in BoxInsetLayout - before, the android:padding="5dp" on your FrameLayout was being ignored (that's why the 'Forehand' was directly on the edge of the app:layout_box="all" edge). Now, it is being respected and your entire inner view is being padded in on all sides, leading to less space overall.
Removing the android:padding="5dp" in your FrameLayout should be enough to restore the previous look.

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);

Resources