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

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.

Related

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?

Adding Android views together

Under iOS, I can have something like this
var myButton = new UIButton(new RectangleF(4,4,100,42));
var myTextView = new UITextView
{
Text = "Hello",
Frame = new RectangleF(4,4,42,21)
};
myButton.Add(myTextView);
this allows me to add a UITextView to a UIButton. Very quick and very simple.
Is there something similar that allows me to do something similar on Android?
This is possible if the type of the view is ViewGroup, otherwise no.
You can overlay views, i.e. when they are both inside of a FrameLayout or RelativeLayout.
A short list of ViewGroup type of views I can remember are:
LinearLayout
RelativeLayout
FrameLayout
GridLayout
CardView
Other special views (limited number of nested views)
DrawerLayout
SlidingPaneLayout
List type of views
ListView
RecyclerView
Spinner
In short what you want is not possible with the two views you gave as an example. However, it is entirely possible to change the look of those views to your liking.

CSS layout in vaadin : the label and button are not comming in line

I am creating label and one button in vaadinn
And when i put these componants on Css Layout the content are comming like
label
button
but i want this is in
-label -buttom
does any one know the solution what css should be applied for that?
best Regards
Arvind
There is two solutions for your problem. You can add StyleName to your CssLayout like this :
myCssLayout.setStyleName("my-layout");
and then add this to your css file:
.my-layout .v-label{
float:left;
}
Or, and this is the right way to resolve your problem, you can use HorizontalLayout instead of CssLayout. It will allow you to put your components in one line.
HorizontalLayout layout = new HorizontalLayout();
layout.addComponent(mybutton);
layout.addcomponent(mylabel);
for the components like you have label and button
label.setWidth(Sizeable.SIZE_UNDEFINED, 0);
then you also have to make this css changes for that component
u-component-label{
display:inline-block;
}

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)

WPF: Accessing Journal history of Frame by external button controls

I am wondering if there is an easy way to use back and forward navigation of the frame journal but using buttons that are not part of the frame. Thank you in advance.
Within the frame set ShowsNavigationUI to false, then create something that looks like:
<Button Content="Back"
Command="{x:Static NavigationCommands.BrowseBack}"
IsEnabled="{TemplateBinding CanGoBack}" />
<Button Content="Next"
Command="{x:Static NavigationCommands.BrowseForward}"
IsEnabled="{TemplateBinding CanGoForward}" />
And then use the appropriate events.

Resources