需要应用样式摆脱入门底线
问题描述:
首先,我是Xamarin Forms的全新品牌,所以要温柔。我需要摆脱为Android中的Entry输入显示的底线。它在iOS中显示得很好。我做了一些研究,发现这一点:需要应用样式摆脱入门底线
<style name="NoBaseline" parent="android:style/Widget.EditText">
<item name="android:background">#D3D3D3</item>
</style>
应该只是简单地使下划线颜色相同的输入框的背景颜色做的伎俩。我已经放在这个代码在我styles.xml文件,但我觉得我需要应用这种风格地方,但我只是不知道在哪里。任何帮助newb将不胜感激。
这里是整个文件:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#FF4081</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="NoBaseline" parent="android:style/Widget.EditText">
<item name="android:background">#D3D3D3</item>
</style>
<style name="AppCompatDialogStyle"
parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<style name="Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>
<style name="MyTheme.Splash"
parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
答
如果你没有看到这个,而你正在研究,here is a solution由dkudelko这可能是稍微简单,如果你只是想删除下划线发布到Github上。
要做到这一点只需在你打电话NoUnderlineEntry然后添加以下代码的Android项目创建一个类。
using <YourApp>.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Entry), typeof(NoUnderlineEntry))]
namespace <YourApp>.Droid
{
public class NoUnderlineEntry : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
Control?.SetBackgroundColor(Android.Graphics.Color.Transparent);
}
}
}
后,你与你的应用程序的名称替换,你会已经创建了覆盖在Android默认Entry
设置控制背景颜色为透明的自定义呈现。
Here is documentation为Entry
创建自定义渲染器。
**注:我没有亲自测试,但多的人评论说,它的工作原理。
请发布您的整个styles.xml代码,以便我们看看您是否做得对。默认样式由Visual Studio的xamarin表单的项目模板自动设置。 –
好的我发布了整个文件 – Ryan
所以我做错了什么? – Ryan