问题
In my xamarin forms project button text are always show in uppercase format.
But I am providing upper and lower case letters in xaml. When I build the solution all the letters are changed to uppercase.
回答1:
I'm guessing you see this on Android as it is the default for button text and has been since Lollipop.
To change this behavior add the following to your styles.xml file which can be found in the Android project under the Resources then values folders
<item name="android:textAllCaps">false</item>
回答2:
The accepted answer assumes the user (even a newbie) to know which style the above code goes in. Even the comments below the accepted answer remain unanswered... I wonder why...
I just started learning Android Xamarin programming and I spent some good 20 mins to figure it out. For any users, specially newbies, see this example.
In your Android project, go to Resources
> values
> styles.xml
and add:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textAppearanceButton">@style/mybutton.text</item>
</style>
<style name="mybutton.text" parent="Base.TextAppearance.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
Screenshot:
回答3:
Recently I had the same issue even though I was using textAllCaps false in my styles. It seems it doesn't work with prerlease version 4.8.0.1238-pre3 of Xamarin.Forms (latest available at the time of posting this). It does work with version 4.7.0.1239 of Xamarin.Forms.
回答4:
An alternative is to simply use TextTransform
property:
<Button Text="Click Me" TextTransform="None"/>
Or in a style definition:
<Style TargetType="Button" x:Key="NoDefaultCapsButton">
<Setter Property="TextTransform" Value="None"/>
</Style>
<Button Text="Click Me" Style="{x:StaticResource NoDefaultCapsButton}"/>
Important Note
Be sure you are using Xamarin.Forms NuGet package 4.8.0.1534 or above, if TextTransform
is not showing for you than clean and rebuild your solution.
回答5:
Solutions for this issue that works for me in android and iOS for material to avoid automatic UpperCase conversion when Visual is set to "Material".
Xamarin.Forms.Android:
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:textAllCaps">false</item>
</style>
Xamarin.Forms.iOS:
[assembly: ExportRenderer(typeof(Button), typeof(ButtonRendererEx), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace GettingStarted.iOS
{
public class ButtonRendererEx : MaterialButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.UppercaseTitle = false;
}
}
}
}
来源:https://stackoverflow.com/questions/47545369/button-text-always-showing-in-uppercase