Data Binding Error Trying to Pass ViewModel into Include Layout with Abstract Variable Type - include

*EDIT: To answer my own question, I had to add EditorViewModel as an import to the parent abstract class in the outer layout, and cast the viewModel to the parent class using app:viewModel="#{((EditorViewModel)viewModel)}", that was it! I swear I don't recall doing this cast before though...*
My problem results because the included layout is defining a type which is the parent abstract class, and NOT the child concrete class, of the viewModel the outer layout is trying to share with the included layout.
I've confirmed that changing the included layout's type to the child concrete class' type fixes the issue, however, it should work with the abstract class type...
Here is how I define my viewModel variable, this is the concrete class in the type below:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel" />
</data>
...
A few statements later I include the layout, attempting to share the viewModel from above:
<include
layout="#layout/layout_spinner_location"
app:viewModel="#{viewModel}" />
Within the included layout the variable viewModel is defined as follows:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EditorViewModel" />
</data>
And of course here's the EquipmentEditorViewModel showing it extends the abstract parent class EditorViewModel (defined as the parent class type above in the included layout):
public class EquipmentEditorViewModel extends EditorViewModel<Equipment> {
The error I receive is:
****/ data binding error ****msg:Cannot find the setter for attribute 'app:viewModel' with parameter type com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel on com.ootpapps.gpeofflinedatacollection.databinding.LayoutSpinnerLocationBinding.
file:C:\Users\Ryan\AndroidstudioProjects\GPEOfflineDataCollection\app\src\main\res\layout\content_equipment_editor.xml
loc:31:33 - 31:41
****\ data binding error ****
As I mentioned above, changing the type in layout_spinner_location to "EquipmentEditorViewModel" fixes the error, HOWEVER, I need to use the abstract type in order to re-use this view as it doesn't always use an EquipmentEditorViewModel, sometimes it needs a "ToolEditorViewModel" or a "MeasurmentEditorViewModel" all of which extend EditorViewModel.
Thank you very much for your help. Maybe I will get lucky and George Mount will stop by.

Just for clarity if anyone comes across this.
Added 3 approaches to tackle the problem, #3 seems to be the winner
This seems to be an issue with the new gradle 3 and upward with the following error: Cannot find the setter for attribute 'app:viewModel'
Before
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{viewModel}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{viewModel}" />
</FrameLayout>
</layout>
include/child xml (layout/request_error_view)
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.BaseViewModel" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/send_request_error_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="#{viewModel.errorVisibility}">
<TextView
android:id="#+id/text_error_sending_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/error_sending_request"
android:textColor="#color/window_primary_text"
android:textSize="#dimen/text_size_large" />
<Button
android:id="#+id/button_try_again"
style="#style/SuperbalistButton.Green.NoInset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/standard_content_margin"
android:onClick="#{viewModel::onClickReload}"
android:text="#string/try_again" />
</LinearLayout>
</layout>
After #1 (2nd variable approach, does not seem to work)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
<variable
name="viewModelBase"
type="com.myapp.android.viewmodel.base.BaseViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{viewModelBase}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{viewModelBase}" />
</FrameLayout>
</layout>
After #2 (casting approach, works)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{((com.myapp.android.viewmodel.base.BaseViewModel) viewModel)}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{((com.myapp.android.viewmodel.base.BaseViewModel) viewModel)}" />
</FrameLayout>
</layout>
After #3 (import and cast approach, works)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.myapp.android.viewmodel.base.BaseViewModel" />
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{(BaseViewModel) viewModel)}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{((BaseViewModel) viewModel)}" />
</FrameLayout>
</layout>

This method works perfectly
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewmodel"
type="com.myapp.data.ViewModel" />
</data>
<include
android:id="#+id/include"
layout="#layout/buttons_layout" />
</layout>
buttons_layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewmodel"
type="com.myapp.data.ViewModel" />
</data>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="#{() -> viewmodel.onClickChangeName()}"
android:text="Change Name"
app:layout_constraintTop_toBottomOf="#id/include"
app:layout_constraintStart_toStartOf="parent"
/>
</layout>
MainActivity
lateinit var dataBinding: ActivityMainBinding
lateinit var viewModel: viewModel
dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
viewModel = ViewModelProvider(this).get(ViewModel::class.java)
dataBinding.include.viewModel = viewModel
dataBinding.viewModel = viewModel
dataBinding.executePendingBindings()

Related

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.

Navigation View app:menu build gradle error

I am trying to use Navigation View in Drawer Layout, but I keep getting errors when building the file.
Here's what my xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_items"
/>
</android.support.v4.widget.DrawerLayout>
This leads to a build gradle error. My menu looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="#+id/menu_bookmark"
android:title="Bookmark" />
<item android:id="#+id/menu_save"
android:title="Save" />
<item android:id="#+id/menu_search"
android:title="Search" />
<item android:id="#+id/menu_share"
android:title="Share" />
</group>
</menu>
When I remove app:menu from the navigationView,the error goes away. What could be wrong?
My fix was that I needed to add app:headerLayout="#layout/my_header_layout" as well.

How to add LinearLayout with rows of imageView In NavigationDrawer

Hi I have the following layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Add The mainmenu-->
// add a linearLayout with 3 row of imagaeView
<!-- The navigation drawer -->
<Mvx.MvxListView
local:MvxBind="ItemsSource MenuItems; ItemClick SelectMenuItemCommand"
local:MvxItemTemplate="#layout/item_menu"
android:id="#+id/left_drawer"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
Problem:
How to add a linearLayout with many rows into this Navigational drawer that using MvxListView.
The NavigationDrawer is on the left side.
Questions:
Must I use FrameLayout?
Can I replace FrameLayout with LinearLayout?
DrawerLayout only supports two child views.
The first element must always be the content view, the second will be what is in the drawer, and you must specify a gravity indicating whether the drawer is coming in from the left or the right.
If you want more than a ListView in the drawer, just wrap the contents in another layout such as RelativeLayout, FrameLayout or LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:orientation="vertical"
android:layout_width="240dp"
android:layout_gravity="start"
android:layout_height="match_parent">
<!-- add other views here -->
<Mvx.MvxListView
local:MvxBind="ItemsSource MenuItems; ItemClick SelectMenuItemCommand"
local:MvxItemTemplate="#layout/item_menu"
android:id="#+id/left_drawer"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"
android:layout_width="match_parent"
android:layout_height="0"
android:layout_weight="1"
android:background="#111" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

How to use selector with xamarin radiobutton to set background colors?

I have two radio buttons, which looks like a normal buttons. I would like to change their background color by using radio_button.xml with selector inside.
If I use little .png image to set background then it works fine.
But I tried similar code to use just colors (integers) and it doesn't work. What I'm doing wrong?
Code with background image:
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:text="LEFT"
android:id="#+id/radioLeft"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#drawable/radio_button"
android:checked="true" />
<RadioButton
android:text="RIGHT"
android:id="#+id/radioRight"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#drawable/radio_button" />
</RadioGroup>
radio_button.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/gray_dot" />
<item android:state_checked="false"
android:drawable="#drawable/blue_dot" />
</selector>
button_colors.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<color name="button_black">#000000</color>
<color name="button_white">#ffffff</color>
<color name="button_blue">#00afdb</color>
<color name="button_gray">#dcdcdc</color>
</resources>
I tried to replace
android:drawable="#drawable/blue_dot"
with
android:background="#color/button_blue"
but it's not working. How to fix?
I used shape xml with color to avoid background images.
radio_button.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/rb_checked" />
<item android:state_checked="false"
android:drawable="#drawable/rb_unchecked" />
</selector>
rb_checked.xml
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/button_blue" />
</shape>
Main.axml
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:checked="true"
android:text="LEFT"
android:id="#+id/radioLeft"
android:button="#android:color/transparent"
android:background="#drawable/radio_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />
<RadioButton
android:text="RIGHT"
android:id="#+id/radioRight"
android:button="#android:color/transparent"
android:background="#drawable/radio_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />
</RadioGroup>
The trick that worked for me was
radioLeft.ButtonDrawable.SetTint(GetColor(Resource.Color.button_blue));
Or whatever color you wish to set, depending on the checked state, eg
radioLeft.ButtonDrawable.SetTint(GetColor(radioLeft.Checked ? Resource.Color.button_blue : Resource.Color.button_gray));

Resources