How to enable Copy Paste for textview in Xamarin Android? - 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?

Related

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.

Xamarin.Forms on iOS: Shrink height of page instead of shifting it up when the softkeyboard appears

Got the problem that the softkeyboard overlaps an entry field placed at the bottom.
XAML code:
<ContentPage.Content>
<AbsoluteLayout VerticalOptions="Fill">
<ScrollView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,0.9">
<Label Text="Heading" />
</ScrollView>
<Entry x:Name="SearchEntry" AbsoluteLayout.LayoutBounds=".5,1,1,.1" AbsoluteLayout.LayoutFlags="All" Placeholder="Suchen..." ReturnType="Done" />
</AbsoluteLayout>
</ContentPage.Content>
I installed the KeyboardOverlap! plugin via nuget. It shifts the whole page upwards till the entry is visible again. The entry is visible, but the top of the page isn't visible anymore because it's shifted up.
Another often mentioned solution is wrapping the pages's content in a ScrollView. Because I definitively need an AbsoluteLayout as root content, that's unfortunately not a solution.
I'm looking for a solution which shrinks the height of the page and don't just shifts it up when the softkeyboard appears.
Why I need this? The page is filled dynmically with search result based on the entrie's input. If there are only few result, they're not visible because of the page's upward shift. The user could think that there aren't any search results. Displaying a text like 'No search results.' above the entry would be a simple solution but is not an option here.
Using this CustomRenderer class in the iOS project instead of the KeyboardOverlap plugin did the trick.
Don't forget to customize line 14 with your concrete page classname(s) where you need the functionality. Otherwise the renderer is called for all pages in your app!
Many thanks to Jack Hua - MSFT!

iOS Toolbar on TextField doesn't hide smoothly when calling blur

I have a TextField set to display a number keypad. By default, this doesn't seem to come with a way for the user to indicate he's finished entering data and then hide it so I added a KeyboardToolbar in the XML which has a DONE button.
When I click the textfield, the number keypad displays the toolbar with the DONE button. When I click "Done", the keypad starts to scroll off the window, but the toolbar doesn't move. When the keypad is fully out of the view, the toolbar then jumps to the bottom of the window and then scrolls off the page too. This causes a noticeable flash for the user.
Any idea how to stop this flash effect from happening? I tried setting opacity 0 on the toolbar when clicked but it doesn't have any effect.
(Expected result is that the toolbar scrolls down with the keypad)
Here's a slowed down GIF to illustrate:
XML:
<TextField id="txt_contactNumber" class="txt_inputshort">
<KeyboardToolbar>
<Toolbar id="numberToolbar" bottom="0">
<Items>
<Button id="flexSpace" systemButton="Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE" />
<Button id="cancelContact" systemButton="Ti.UI.iPhone.SystemButton.DONE" />
</Items>
</Toolbar>
</KeyboardToolbar>
</TextField>
JS:
$.cancelContact.addEventListener('click', function(){
$.txt_contactNumber.blur();
});
TSS:
"#txt_contactNumber": {
keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD,
}

How to scroll to the last appended piece of text on a TextView?

So I have a multi-line TextView on my C# Android application. I'm using this as a kind of "status" logger..
So, I might have things like this:
Probing widgets
Proper widget found
Configuring widget
Where each line might take a few seconds to appear because it's something relatively slow.
So, I have a TextView inside of a ScrollView like so:
<ScrollView
p1:minWidth="100px"
p1:minHeight="100px"
p1:layout_width="fill_parent"
p1:layout_height="match_parent"
p1:id="#+id/scrollView1">
<TextView
p1:id="#+id/terminalOutput"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent" />
</ScrollView>
This works fine and I can just append to the TextView using the .Append method. However, the problem is that eventually there are so many status messages that the text goes down and off the screen. At this point, you have to manually drag in the scroll view to read the latest status messages.
I want it so that whenever a piece of text is appended and it goes off screen for it to scroll the scrollview down so that users can read the latest message without manual scrolling.
How can I do this?
This is what I've tried so far:
Logger = new TextLogger((s) =>
{
RunOnUiThread(() =>
{
var textview=FindViewById<TextView>(Resource.Id.terminalOutput);
textview.Append(s + "\n");
var scrollview=FindViewById<ScrollView>(Resource.Id.scrollView1);
scrollview.ScrollTo(0,scrollview.Bottom);
textview.ScrollTo(0, textview.Bottom);
});
});
This kind of works, but it seems like it never quite scrolls to the actual bottom. It scrolls down, but is always like 2 lines away from the bottom, leaving some text still hidden
Try using ScrollView.FullScroll method instead:
scrollview.FullScroll(Android.Views.FocusSearchDirection.Down)

How can I place a Firefox toolbar button close to the address bar

I am developing a Firefox addon with a toolbar button. I would like this button to appear close to the browser's address bar and in the same line or row, either at its left or at its right. For instance, like the page saver addon from Pearl Crescent.
But my code just manages to create an empty new row and places the toolbar button in it. A terrible waste of vertical space.
I am using the following overlay in my xul file:
<overlay id="browseye-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<toolbox id="navigator-toolbox">
<toolbar id="my-toolbar"
class="chromeclass-toolbar"
toolbarname="my Toolbar"
hidden="false"
mode="full"
defaultset="my-toolbar-button"
persist="hidden collapsed">
<toolbarbutton id="my-toolbar-button"
tooltiptext="my Toolbar"
orient="horizontal"
mousethrough="never"
oncommand="my.onToolbarButtonCommand()">
</toolbarbutton>
</toolbar>
</toolbox>
</overlay>
Could anybody please help me?
You need to add your button to the toolbarpalette tag without adding a new toolbar, see code example in https://developer.mozilla.org/en/XUL_School/Adding_Toolbars_and_Toolbar_Buttons#Adding_a_new_toolbar. Then the user will be able to position your button anywhere using "Customize toolbar" dialog.

Resources