I have a Xamarin.Android project that has been in development for awhile. I went to use my first Android Switch control yesterday. When the UI rendered on my device (I don't use Xamarion.Android preview editor cause it continually crashes VS). It only showed off/on text, and no UI for the switch control at all. This seemed to happen regardless of what width/height I specified for the control etc.
I created a new Android project, dropped the switch on and it renders fine. I then changed the API level to match my API level (21) and it rendered a bit differently, but again rendered fine.
After much debugging and frustration I discovered that if I implement by own custom drawables for the Thumb and Track that the UI seems to function.
So I was wondering: Has anyone run into this before? Do we know what the cause is?
I wanted to document this in case anyone else ran into problems.
Someone requested layout code. There's not much, but here it is:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Yes I managed to get this figured out, then forgot to update this. Unfortunately I couldn't get it working through Xamarin. Something was messed up and I didn't know what it was and couldn't get an answer from anyone. So: I drew it myself (which I ended up needing to do anyway for my app).
In my layout for the switch I set these two drawables:
android:thumb="#drawable/SwitchThumbTrack"
android:track="#drawable/SwitchTrack"
Then in my code when someone toggles it I have a drawable for SwitchTrackOn as well. If you want, here's some code to make it kind of look like an iOS switch:
SwitchThumbTrack.xml
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#FFFFFF"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
SwitchTrack
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="15dp"/>
<stroke android:width="1dp" android:color="#ffffff"/>
<solid android:color="#0000FF" />
<size android:width="80dp" android:height="30dp"/>
</shape>
SwitchTrackOn
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="15dp"/>
<stroke android:width="1dp" android:color="#color/White"/>
<solid android:color="#4ED164" />
<size android:width="80dp" android:height="30dp"/>
</shape>
Hope this helps!
James
For me, adding the following worked:
android:minWidth="100dp"
android:minHeight="50dp"
Related
hello I am trying to make my code in the axml file more readable I have a lot of switches in my program and I want to shrink this part of the code. I read something about it and I found
<!--#region Name-->
My Code
<!--#endregion-->
But it is referred as a normal comment. Could you help me out? I am using Visual Studio 2017 in case it is important to mention.
# region in axml file for xamarin.android
If you want to make the .axml file more readable, you could click the indent button: Effect.
Or you could use the <include/> tag embed another layout inside the current layout to make it more readable. For example, create a titlebar.axml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/titlebar_bg"
tools:showIn="#layout/activity_main" >
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
Use it in another layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
Update:
I think the XAML Regions is what you are looking in your .axml file.
Update 2:
Install this plugin for your Visual Studio, close all your Visual Studio windows and reopen the VS. Then, you could the the #Region function for your
<!-- Region (Any Text You Want) -->
Your Code
<!-- EndRegion -->
I have a Switch and a TextInputEditText. Both 'Enabled' are bound to the same field in the viewmodel.
When the activity is loaded, the bound field is set to false. The Switch is disabled as expected. However, the TextInputEditText is enabled. The 'Clickable' has the same issue. Text is bound successfully.
After changed the bound field to true and then false, the TextInputEditText Enable & Clickable work correctly. It seems that it only happens when it is loaded initially.
<android.support.v7.widget.SwitchCompat
style="#style/EntryTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxLang="Text LabelDeferArrivalNotice"
local:MvxBind="Checked RouteMarker.DeferArrivalNotice; Enabled RouteMarker.ArrivalNotice" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/edittext_route_marker_EffectiveFromDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="false"
android:focusableInTouchMode="false"
style="#style/EntryTextStyle"
local:MvxLang="Hint LabelEffectiveFromTime"
local:MvxBind="Text DateTimeToString(RouteMarker.EffectiveFromDateTime);
Enabled RouteMarker.ArrivalNotice;
Clickable RouteMarker.ArrivalNotice;
Click PromptDeferTimeCommand" />
Is there anything special I have to do with the TextInputEditText?
Thanks
This is an issue with MvvmCross, as Stuart said, there are some interaction between ICommand.CanExecute and the Enabled property. Switching the binding to :
local:MvxBind="Click PromptDeferTimeCommand;Enabled RouteMarker.ArrivalNotice;Clickable RouteMarker.ArrivalNotice;"
Hope to help somebody who searched this problem.
I'm trying to bind LinearLayout to show/hide in accordance with ViewModel State.
For some reason it works great for buttons and textviews but not for LinearLayout.
What could be the reason?
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visibility WaitingForConfirmation">
I just tried a quick test using the bool Visible pseudo-property and it worked for both TextView and for LinearLayout
<TextView
android:text="Random text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Visible Generosity > 12" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:background="#ff0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visible Generosity > 12" />
The Visibility property binds to the same underlying Android hide/display mechanism - it just uses the Visibility plugin to convert bool->Visibility enum - so the code should work for that too...
Update: I also tried within the Droid sample https://github.com/slodge/MvvmCross-Tutorials/tree/master/ValueConversion
Within this I just changed the displayed view to LinearLayout in https://github.com/slodge/MvvmCross-Tutorials/blob/master/ValueConversion/ValueConversion.UI.Droid/Resources/Layout/View_Visibility.axml
This sample worked fine:
What is WaitingForConfirmation? I suspect it's a bool, in which case you will need to use a visibility converter, just as you do in Windows binding. A standard visibility converter is provided in the Visibility plugin, and can be used:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#ff0000"
local:MvxBind="Visibility MakeItVisible, Converter=Visibility" />
One final note: MvvmCross does continue to adapt (and hopefully improve) its binding type conversion - so at some point you may be able to get away with using bools with Visibility enums - but this probably isn't ever going to be recommended practice - normally it's better to use value converters to take control of your binding operations (just like in Windows).
Currently I have a XUL notification box being displayed as I am developing a Firefox Addon. At the moment the notification box will only display at the bottom of the browser and cannot find any information about changing the position to the top of the browser.
I know you can use priority_high etc... but it only seems to add this again at the bottom of the browser.
Code:
<notificationbox flex="0.1">
<browser src="http://www.mozilla.org"/>
<notification type="warning" label="Test"/>
</notificationbox>
Any help will be grateful.
I have tested with XUL Explorer, I could change the positions successfully.
Here is the code:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- your code here -->
<stack>
<hbox flex="1" left="100" right="10" top="50" bottom="10">
<notificationbox flex="0.1" >
<browser src="http://www.mozilla.org"/>
<notification type="warning" label="Test" />
</notificationbox>
</hbox>
</stack>
</window>
I am new in monodevelop/monoandroid.I need code for showing multiline text in textview I have tried bellow but still its not working.I think there should be some code that I have to include in .cs file,but I am not getting what to use there.
I have used c# code also but its not working. I think ellipsize is a android attribute thats why its not working.Please give me some solution.
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dip"
android:orientation="vertical"
android:layout_gravity="center" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="10dip">
<TextView
android:id="#+id/tv_policy1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information for Personal non-commercialaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa use only sdfjkj asdfjklfj sdfjkljdf sdfjkljflkj sdfskjfkl sdfjklsdjf sdfkljsdklfj sdfjhsdkfh"
android:textColor="#000000"
android:maxLines="3"
android:singleLine="false"
android:textSize="14dip" />
</RelativeLayout>
</ScrollView>
Please advice....
Thanks in advance!
Try this format:
<ScrollView>
<RelativeLayout>
<TextView/>
<TextView/>
<RelativeLayout/>
<ScrollView/>
Then you can use the align methods given in a RelativeLayout.
Edit:
Explain what your problem is! Do you get an error when compiling or is the text not shown properly? Be more specific.
Also, why do you use attributes like : android:maxLines="3" or android:singleLine="false" or android:layout_height="60dip" in your TextView. Translated this means: The text must have more than one line but a maximum of 3. Also it can't be longer than 60dip.
Depending on the Text that are very strict rules. Use these rules android:layout_width="match_parent" android:layout_height="wrap_content" to make sure that the text can be displayed correctly, remove the attributes I mentioned before in your TextView.