I would like to display a some text that when clicked will redirect me to a website. I am writing by android app with C# (Xamarian studio).
<TextView
android:id="#+id/rsstitle"
android:autoLink="web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="16dip"
android:textStyle="bold" />
view.FindViewById<TextView> (Resource.Id.rsstitle).Text = values [position];
//values[position] contains a title string eg "Google"
links[position] contains a uri eg "https://www.google.co.nz/"
How do I make it so that "Google" is displayed but when clicked directs to https://www.google.co.nz/
Found my solution:
String linkText = "" + values [position] + " ";
link.TextFormatted = Html.FromHtml(linkText);
link.MovementMethod = LinkMovementMethod.Instance;
Related
How can you set AnimateLayoutChanges to True via C# in Xamarin.Android for a linear layout? I cannot use an xml resource file when building this custom view. The xml for this linear layout would be this:
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:id="#+id/linearLayoutOne"
android:layout_weight="1"/>
All of the other attributes can be set via C# via the following:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent, 1);
linearLayoutOne = new LinearLayout(Context);
linearLayoutOne.Orientation = Orientation.Vertical;
linearLayoutOne.LayoutParameters = layoutParams;
linearLayoutOne.SetMinimumHeight(25);
linearLayoutOne.SetMinimumWidth(25);
So how in the world do you set AnimateLayoutChanges in C#?
The C# equivalent of setting that is:
linearLayoutOne.LayoutTransition = new LayoutTransition();
linearLayoutOne.LayoutTransition.EnableTransitionType(LayoutTransitionType.Changing);
Looking to create a popup where the user must type 'CONFIRM' to continue. I know how to develop a popup with 'CONTINUE' or 'CANCEL' on it but unsure of how to implement one that checks/validates the users input.
Using native Xamarin on Android with C#.
This is what I have so far. I just need some way of comparing what the user has input to the word CONFIRM
EditText et = new EditText(this);
AlertDialog.Builder ad = new AlertDialog.Builder (this);
ad.setTitle ("Type text");
ad.setView(et); // <----
ad.show();
Create a layout with EditText named CustomDialog.xml.
<?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">
<EditText
android:id="#+id/editText_Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Code in MainActivity.cs OnCreate method.
var editText = LayoutInflater.Inflate(Resource.Layout.CustomDialog, null);
var ad = (new AlertDialog.Builder(this)).Create();
ad.SetTitle("Type text");
ad.SetView(editText); // <----
ad.SetButton("Confirm", ConfirmButton);
ad.Show();
The code of ConfirmButton.
void ConfirmButton(object sender, DialogClickEventArgs e)
{
var dialog = (AlertDialog)sender;
var username = (EditText)dialog.FindViewById(Resource.Id.editText_Name);
var name = username.Text;
if (name=="hello")
{
}
}
You could get the text of EditText now.
Updated:
In Xamarin.forms, when you want to display a prompt, you could use DisplayPromptAsync.
protected override void OnAppearing()
{
base.OnAppearing();
PopUp();
}
public async void PopUp()
{
string s = await DisplayPromptAsync("Pop up Window", "Type text:", "Confirm", keyboard: Keyboard.Text);
if (s == "hello")
{
//do something here...
}
}
Display Pop-ups: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/pop-ups
I made a Custom Layout to add a badge to a tab on Android. This badge is a TextView.
How do I bind this component?
It's possible?
My custom badge layout:
<LinearLayout
android:id="#+id/badgeCotainer"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginStart="90dp"
android:background="#drawable/notifications_background"
android:gravity="center"
android:layout_gravity="right"
android:minWidth="16dp">
<TextView
android:id="#+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#011f7a"
android:textSize="10sp"
android:text="0"
app:MvxBind="Text ContMaterial"/>
</LinearLayout>
My Activity: use MvxViewPagerFragmentInfo
private void InitTabs()
{
var viewPager = FindViewById<ViewPager>(Resource.Id.materiais_viewpager);
if (viewPager != null)
{
var fragments = new List<MvxViewPagerFragmentInfo>
{
new MvxViewPagerFragmentInfo("Requisição",
typeof(CadastraRequisicaoFragment), ViewModel),
new MvxViewPagerFragmentInfo("Materiais",
typeof(ListaMateriaisFragment), ViewModel),
};
viewPager.Adapter = new MvxCachingFragmentStatePagerAdapter(this, SupportFragmentManager, fragments);
}
var tabLayout = FindViewById<TabLayout>(Resource.Id.requisicao_tabs);
tabLayout.SetupWithViewPager(viewPager);
tabLayout.GetTabAt(1).SetCustomView(Resource.Layout.tab_header_badge);
}
On view Model I used raisedPropertyChanged()
Badge appears normally, just don't change value.
Tablayout
Out of the box there is nothing in mvvmcross to bind the content of a TabLayout when you provide a custom view. You could however try something custom using MvxFrameControl
Basically, replace your LinearLayout by the MvxFrameControl, then after
tabLayout.SetupWithViewPager(viewPager);
inflate your custom view using the BindingInflate method, and set a value to your MvxFrameControl's BindingContext, then set your custom tablayout view with the result that operation.
That might do the trick.
Another way to do it, is to listen to your ViewModel's "PropertyChanged" events in your Activity, and manually make changes to your tab layouts when it applies.
I've been looking at the Playground project on MvvmCross (https://github.com/MvvmCross/MvvmCross/tree/develop/Projects/Playground)
The way to have a fragment loaded into the tabs is to set the attribute the following way:
[MvxTabLayoutPresentation(TabLayoutResourceId = Resource.Id.tabs, ViewPagerResourceId = Resource.Id.viewpager, Title = "Tab 1", ActivityHostViewModelType = typeof(TabsRootViewModel))]
[MvxTabLayoutPresentation(TabLayoutResourceId = Resource.Id.tabs, ViewPagerResourceId = Resource.Id.viewpager, Title = "Tab 1", FragmentHostViewType = typeof(TabsRootBView))]
[Register(nameof(Tab1View))]
public class Tab1View : MvxFragment<Tab1ViewModel>
My questions is, besides the title that can be specified on the MvxTabLayoutPresentation, how can I add and icon to each one of the tabs?
That is not provided out-of-the-box and it's more about TabLayout customization.
You can achieve it like this.
Create a CustomView for your tab layout item, myCustomTab.axml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="12"
android:textStyle="bold" />
Then in your view that has the TabLayout you configure it on the OnCreate / OnCreateView:
var tabLayout = view.FindViewById<TabLayout>(Resource.Id.tabs);
var customTab = inflater.Inflate(Resource.Layout.myCustomTab, null);
customTab.Text = "MyText";
// this sets the icon above the text
customTab.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.my_icon, 0, 0);
tabLayout.GetTabAt(0).SetCustomView(customTab);
Obviously you have to do this as many times as tab layout items you have.
Furthermore using this you can add any customization to your tab layout items.
Source (in java): https://mobikul.com/make-custom-tabs-icons-android/
HIH
I'm building a text to speech app for android. I have a functioning EditText window. Whatever is typed into the window is spoken at the click of a button. What I want to do next is to build a sentence for output by adding text to the EditText window through button clicks.
This is my "speak" function. Can I manipulate and append to the editText.Text to accomplish my goal?
speak.Click += delegate
{
if (!string.IsNullOrEmpty(editText.Text))
textToSpeech.Speak(editText.Text, QueueMode.Flush, null);
};
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="What would you like to say?" />
<Button
android:text="Speak"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/speak" />
I may be misunderstanding the question but this may work for you:
String text = "whatever";
if (!TextUtils.isEmpty(text)) {
editText.append(text);
}
You can do something like this
String speechText = editText.Text;
buildSentence.Click += delegate{
String sentenceToBuild = "This is the sentence I want to build";
sentenceToBuild += speechText;
editText.Text = sentenceToBuild;
}