阴影控制和自定义

时间:2017-09-20 09:45:13

标签: android forms xamarin shadow renderer

我正试图为我的按钮获得一个阴影,但它不起作用,我不知道为什么。因为我已经看过很多帖子询问如何取消它,我不是为什么但是从一开始我没有为我的按钮设置阴影。如果有人可以提供帮助......我也试图为我的StackLayouts实现这样的目标:

enter image description here

最后一个问题是避免开另一篇文章: 如何在关注此条目时让占位符在条目上移动?

我的按钮代码

我上课了:

public class ButtonComponent : MR.Gestures.Button
    {

    }

自定义渲染器:

[assembly: ExportRenderer(typeof(ButtonComponent), typeof(ButtonComponentRenderer))]
namespace MyApp.Droid
{
    public class ButtonComponentRenderer : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.Elevation = 9;
            }
        }
    }
}

按钮init:

// Login button
        _okButton = new ButtonComponent
        {
            Text = "Validate",
            BackgroundColor = Constants.PrimaryColorOrange,
            HeightRequest = 50,
            WidthRequest = 180,
            HorizontalOptions = LayoutOptions.CenterAndExpand,
            TextColor = Color.White 
        };

这是我的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">#FFA100</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#FF8000</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FFA500</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">#FFA100</item>
  </style>
  <style name="MainTheme.Splash" parent="MainTheme">
    <!--<style name="MainTheme.Splash" parent="Theme.AppCompat.Light.DarkActionBar">-->    
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="colorAccent">#FF8000</item>
    <!--<item name="android:windowActionBar">false</item>-->
    <!--<item name="colorPrimary">#FFA100</item>-->
  </style>  
</resources>

如果有人问,MainActivity

 [Activity(
        Label = "App", 
        Icon = "@drawable/icon", 
        Theme = "@style/MainTheme.Splash", 
        MainLauncher = true,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
And androidmanifest

`<application android:label="MyApp.Droid" android:largeHeap="true" android:icon="@drawable/icon" android:theme="@style/MainTheme" >`
Android AppCompat v7 25.4.0.2

谢谢大家。

0 个答案:

没有答案