How to highlight a pressed cardView on IceCreamSandwich (Android 4.0.4) - highlight

This is my CardView layout :
<it.gmariotti.cardslib.library.view.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_cardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
card:card_layout_resourceID="#layout/cardview_history"
style="#style/list_card.base"/>
Based on that layout, my CardViews layout is correctly displayed but don't get highlighted when pressed.
On IceCreamSandwich (API 15 : 4.0.4) and unlike later OS versions, if we click on a CardView, it won't be highlighted. So I tried to explicitly add a background card_selector to my CardView.
android:background="#drawable/card_selector"
I'm using the default existing drawable available in the cardslib resource (card_selector.xml) :
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime">
<item android:state_activated="true" android:drawable="#drawable/activated_background_card"/>
<item android:state_pressed="true" android:drawable="#drawable/pressed_background_card"/>
<item android:drawable="#drawable/card_background"/>
</selector>
But here is how my CardViews layout become, and as you can see, one of them is pressed but not correctly highlighted.
Is there a solution to make my CardView highlight correctly when pressed?

Related

MotionLayout as parent of CoordinatorLayout broke scrolling

When CoordinatorLayout is used inside of MotionLayout and while screen scrolling some view requests layout (via requestLayout() function), the rest of the scrolling is broken.
The layout structure is:
<MotionLayout>
<View/> <!-- Animated with motion scene -->
<CoordinatorLayout>
<AppBarLayout>
<ImageView/> <!-- Requests layout -->
</AppBarLayout>
<RecyclerView/>
</CoordinatorLayout>
<MotionLayout>
The MotionScene:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="#id/end"
app:constraintSetStart="#id/start" />
<ConstraintSet android:id="#+id/start">
<Constraint android:id="#id/background">
<PropertySet android:alpha="0" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="#+id/end">
<Constraint android:id="#id/background">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>
</MotionScene>
The animation progress is calculated like this:
appBarLayout.addOnOffsetChangedListener(OnOffsetChangedListener { _, verticalOffset ->
motionLayout.progress = -verticalOffset / appBarLayout.totalScrollRange.toFloat()
})
The key points are next:
AppBarLayout (as part of Coordinator layout) notifies (thru listener) about scrolling position changes.
MotionLayout changes its progress according to the scrolling position mentioned above.
While scrolling some view should call requestLayout() - in my example it happens on ImageView click
After that, any following scrolling will be broken and the layout looks invalid.
To identify the root cause I've tried to remove the line with MotionLayout.setProgress() with the rest of the code remains unchanged. And after that scrolling has worked as expected. After this I decided to put back MotionLayout.setProgress() and this time I've removed View.requestLayout(). And this time scrolling works as expected too. But when I'm trying to put back both MotionLayout.setProgress() and View.requestLayout() the scrolling broke.
Also I've submitted a bug to the Google issue tracker: https://issuetracker.google.com/u/1/issues/178976381
By default MotionLayout ignores requestLayout during transitions. This is done for performance. To enable in your tag add
layoutDuringTransition="honorRequest"

Xamarin.Android: When I create a button programmatically, why does it have a margin?

EDIT: I think I figured it out. It was the background in the xml that was causing the difference.
Q:
I'm trying to add buttons to my app dynamically. (I need to create 1-6 buttons)
When I try to create a button in XML (to test the appearance), it looks like this:
Buttons created in XML
Here's the xml I used to create that:
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
android:text="add button"
/>
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
android:text="add button"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
But when I try to create it programmatically, the buttons have a margin on the sides and they look a bit raised up.
How do I get then programmatic buttons to look the same as the XML buttons?
Is there some extra styling happening somewhere?
Dynamically created buttons (below XML buttons)
Here's the code I used to create the buttons dynamically:
var button = new Button(this);
var height = Utility.DpToPx(this, 100);
var width = ViewGroup.LayoutParams.MatchParent;
var layoutParameters = new LinearLayout.LayoutParams(width, height);
button.LayoutParameters = layoutParameters;
button.Text = "Test";
EDIT:
I think I figured it out. It's the background that I put in the xml that is causing the different effect:
android:background="#android:color/darker_gray"
My confusion was caused by the fact that I did not add a background color to the buttons that I created programatically. That is why the appearances were different.

MvxSpinner item should be blank until not select from dropdown list

I'm using MvxSpinner and just want to show drop down selected value over spinner.Currently its showing first item from dropdown list but i want to show blank as i didn't choose any value from dropdown.
Spinner
<MvvmCross.Binding.Droid.Views.MvxSpinner
android:id="#+id/mySpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxDropDownItemTemplate="#layout/myspinner_item"
local:MvxItemTemplate="#layout/myspinner_item"
android:layout_marginLeft="0dp"
android:dropDownWidth="257dp"
android:dropDownSelector="#drawable/list_item_selector"
android:layout_centerInParent="true"
android:spinnerMode="dropdown"
local:MvxBind="ItemsSource MyItems; HandleItemSelected SelectCommand" />
myspinner_item
<?xml version="1.0" encoding="utf-8"?>
<MvvmCross.Binding.Droid.Views.MvxLinearLayout 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="wrap_content"
android:background="#drawable/list_item_selector"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="32dp"
android:textSize="15sp"
android:textColor="#de000000"
android:lineSpacingExtra="5sp"
android:singleLine="true"
android:text=""
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_marginLeft="24dp"
local:MvxBind="Text Description; Typeface StringToFont('Effra_Rg')" />
</MvvmCross.Binding.Droid.Views.MvxLinearLayout>
It's showing the first item because it's bound to the item list. Might be considered bad practice by some, but if your goal is for it to stay blank until chosen, have you tried adding a new item to the front of your list with a blank description?

How to enable Copy Paste for textview in Xamarin Android?

I have RecyclerView, using ViewHolder contains CardView with TextView.
For the textview, I have enabled 'textIsSelectable' property which allows you to select text and copy it.
Below is my textview:
<TextView
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtNFDescription"
android:textColor="#3f4852"
android:bufferType="spannable"
android:textIsSelectable="true" />
It works for me if I land on this page for the first time.
But if i scroll up this recycler view
OR
Navigate to another page and then land to the same page where i have this implementation. It stops working.
And OUTPUT window gives me this error when I longpress on textview after navigating or scrolling:
08-17 12:05:20.031 W/TextView(10128): TextView does not support text selection. Selection cancelled.
Any Suggestions or solutions why is this happening?

MVVMCross Databinding Lists with EditText

I've been playing with the monodroid/monotouch for a while now and having decided to jump from monocross to mvvmcross, I've hit a bit of a problem.
I have a domain model which contains a sub property which is a list of another domain object. Has-Many if you will. What I'm trying to do is display the aggregate root object and allow the user to fill in the details of the sub object.
public class objA
{
public List<objB> mySubObjs
}
I pretty easily got this hooked up using the MvxBindableListView. Except I couldn't bind to objA.mySubObjs, I had to bring the list up a level in the ViewModel and bind to that? Anyway, the issue I faced is that my itemtemplate for the List looked a bit like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="a)"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText xmlns:local="http://schemas.android.com/apk/res/x.x.x.x"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
local:MvxBind="{&apos;Text&apos;:{&apos;Path&apos;:&apos;Name&apos;}}" />
</RelativeLayout>
Which renders fine, but is just not useable. When I click on the editText control is brings up the softkeyboard and in doing so loses focus. I've read a couple of articles about EditText in ListView's don't work too well.
Therefore I tried building up the List view manually by binding to specific items i.e. objA.mySubObjs[0].Name, but this doesn't seem to reflect back in the ViewModel.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Question"
android:textAppearance="?android:attr/textAppearanceSmall"
local:MvxBind="{&apos;Text&apos;:{&apos;Path&apos;:&apos;Items[0].Name&apos;}}" />
I'm at a bit of a loss and didn't really want to go down the route of flattening the List within my ViewModel to accomodate the Android View.
Any help would be appreciated
Does this help - Focusable EditText inside ListView
. Except I couldn't bind to objA.mySubObjs,
on other points, feel free to ask this as a separate question - it should be possible...

Resources