Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-Xamarin.Forms上的边框被忽略_Android_Xamarin_Xamarin.android_Xamarin.forms - Fatal编程技术网

Android-Xamarin.Forms上的边框被忽略

Android-Xamarin.Forms上的边框被忽略,android,xamarin,xamarin.android,xamarin.forms,Android,Xamarin,Xamarin.android,Xamarin.forms,我正在尝试使用Xamarin.Forms构建一个带有绿色边框的圆形按钮,使用我在以前的项目中使用的方法,将BorderRadius、BorderColor等值添加到button元素中 请考虑以下代码: Button goButton = new Button { Text = "GO!", TextColor = Color.White, FontSize = 75, HeightRequest = 200, WidthRequest = 200,

我正在尝试使用Xamarin.Forms构建一个带有绿色边框的圆形按钮,使用我在以前的项目中使用的方法,将BorderRadius、BorderColor等值添加到button元素中

请考虑以下代码:

Button goButton = new Button
{
    Text = "GO!",
    TextColor = Color.White,
    FontSize = 75,
    HeightRequest = 200,
    WidthRequest = 200,
    BorderRadius = 100,
    BorderWidth = 10,
    BorderColor = Color.Green,
    BackgroundColor = Color.Red
};
上面的代码提供了以下不希望的输出:

我曾尝试用XAML重新编写,但也遇到了同样的问题,我还检查了我的Xamarin版本(以及NuGet Xamarin.forms包)是否是最新的。然而在iOS版本上,一切看起来都是正确的(我想这是第一次!)

如果您能协助查找问题并解决此问题,我们将不胜感激

建议编辑:

请在下面找到my styles.xml

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <style name="MainTheme" parent="MainTheme.Base">
    </style>

    <!-- Base theme applied no matter what API -->
    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">

        <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
        <item name="windowNoTitle">true</item>

        <!--We will be using the toolbar so no need to show ActionBar-->
        <item name="windowActionBar">false</item>

        <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->

        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">#2196F3</item>

        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">#1976D2</item>

        <!-- colorAccent is used as the default value for     colorControlActivated
     which is used to tint widgets -->
        <item name="colorAccent">#FF4081</item>

        <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
        <item name="windowActionModeOverlay">true</item>

        <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    </style>

    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#FF4081</item>
    </style>

</resources>

真的
假的
#2196F3
#1976D2
#FF4081
真的
@样式/应用程序对话框样式
#FF4081

带边框的
按钮
s对我来说很好。。。也许可以尝试一些更合理的值:

Button button = new Button {
    BorderWidth = 1,
    BorderColor = Color.Green,
    BackgroundColor = Color.Transparent,
    Text = "GO!",
    TextColor = Color.White,
}
这就是我的
按钮中的所有内容,边框显示为ok。想知道
BackgroundColor=Color.Transparent
是否会对你产生影响

*编辑:添加注释作为答案。根据post,为
按钮添加一个完全空的自定义渲染器可能有助于:

[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(GenericButtonRenderer))]

namespace Express.CustomRenderers {
    public class GenericButtonRenderer : Xamarin.Forms.Platform.Android.ButtonRenderer { }
}

不幸的是,我得到了完全相同的问题,我原来有透明的,并将其移动到红色,以便屏幕截图显示更清晰。@A我将假设这是一个与您添加的Android主题和/或样式有关的问题。可能会发布您在
/values/
/values-21/
目录中的
Styles.xml
代码。@A您是否可以尝试在项目中更新到最新版本的Xamarin表单,看看这是否有帮助?我确实看到了一两个关于相关问题的错误。首先,感谢您坚持这一点,我对此表示感谢。其次,我有一个PCL,所有这些都在2.3.3.168上,我相信这是最新发布的稳定版本。@Aphire Nice find!我没看到那个。我不知道这个人是否在使用材料。也许值得一试。