第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Xamarin Forms 平臺(tái)上點(diǎn)擊 android 按鈕時(shí)如何刪除動(dòng)畫(huà)/陰影效果

在 Xamarin Forms 平臺(tái)上點(diǎn)擊 android 按鈕時(shí)如何刪除動(dòng)畫(huà)/陰影效果

C#
慕碼人8056858 2021-10-24 17:19:48
我需要?jiǎng)h除從 xamarin 表單中點(diǎn)擊我的 android 按鈕時(shí)出現(xiàn)的陰影。(如上圖所示。當(dāng) yes 和 no 原本是相同顏色時(shí)。按下 no 時(shí),會(huì)在其上投射陰影,使其顏色變暗)我按照如何刪除 Xamarin Forms 上按鈕的陰影中所述的示例進(jìn)行操作, 但由于我的按鈕顏色應(yīng)該是紅色,因此我沒(méi)有將 PCL 中的背景顏色更改為紅色。但是當(dāng)點(diǎn)擊時(shí),陰影仍然出現(xiàn)在 android 按鈕上。然后,我點(diǎn)擊了這個(gè)鏈接:https : //forums.xamarin.com/discussion/122752/removing-shadow-from-android-buttons 但我按鈕上的陰影仍然存在。我認(rèn)為就像鏈接中所說(shuō)的那樣,因?yàn)槲业?xamarin 表單版本是 2.5.0.280555,所以他們提供的解決方案將不起作用。如果我仍然需要將我的 xamarin 表單版本保持為 2.5.0.280555,那么在點(diǎn)擊我的 Xamarin.Forms 項(xiàng)目時(shí)需要?jiǎng)h除 android 按鈕陰影時(shí),是否有人對(duì)我可能做的事情有任何建議或解決方案?它在這里說(shuō)該問(wèn)題已在以后的版本中解決:https : //github.com/xamarin/Xamarin.Forms/issues/1954所以我升級(jí)到 2.5.1.52 以獲取 xamarin 表單。但是在android平臺(tái)上點(diǎn)擊按鈕時(shí),我仍然看到按鈕上的陰影。我的代碼更改如下:在 Style.xml<resources>    <style name="MyTheme" parent="MyTheme.Base">        </style>    <!-- Base theme applied no matter what API -->    <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"><item name="android:buttonStyle">@style/NoShadowButton</item>    </style><style name="NoShadowButton" parent="android:style/Widget.Button">        <item name="android:stateListAnimator">@null</item>    </style></resources>我什至實(shí)現(xiàn)了一個(gè)自定義渲染器[assembly: ExportRenderer(typeof(FlatButton), typeof(UnanimatedButtonRenderer))]namespace RideNow.Droid{  public class UnanimatedButtonRenderer : ButtonRenderer    {        protected override void OnDraw(Android.Graphics.Canvas canvas)        {            base.OnDraw(canvas);        }        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)        {            base.OnElementChanged(e);            if (this.Control != null && this.Element != null)            {                var nativeButton = (Android.Widget.Button)Control;                nativeButton.SetShadowLayer(0, 0, 0, Android.Graphics.Color.Transparent);                    }                }            }        }    }}其中 Flatbutton 只是一個(gè)自定義按鈕,繼承自 xamarin 表單的按鈕,沒(méi)有任何附加組件。但似乎沒(méi)有任何效果
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊

在您的自定義渲染器中嘗試以下操作:


    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)

    {

        base.OnElementChanged(e);


        if (this.Control != null && e.NewElement != null)

        {

            if (Build.VERSION.SdkInt > BuildVersionCodes.Lollipop)

            {

                this.Control.StateListAnimator = null;

            }

            else

            {

                this.Control.Elevation = 0;

            }

        }

    }

這是我在 Android 6 模擬器上看到的:

http://img1.sycdn.imooc.com//6175259b00015f7701800019.jpg

如果您希望單擊時(shí)絕對(duì)沒(méi)有顏色變化,您可以進(jìn)一步自定義渲染器:


public class UnanimatedButtonRenderer : ButtonRenderer

{

    private FlatButton TypedElement => this.Element as FlatButton;


    public UnanimatedButtonRenderer(Context context) : base(context)

    {

    }


    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)

    {

        base.OnElementChanged(e);


        if (this.Control != null && e.NewElement != null)

        {

            this.UpdateBackground();


            if (Build.VERSION.SdkInt > BuildVersionCodes.Lollipop)

            {

                this.Control.StateListAnimator = null;

            }

            else

            {

                this.Control.Elevation = 0;

            }

        }

    }


    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)

    {

        base.OnElementPropertyChanged(sender, e);


        if (e.PropertyName.Equals(VisualElement.BackgroundColorProperty.PropertyName) ||

            e.PropertyName.Equals(Button.CornerRadiusProperty.PropertyName) ||

            e.PropertyName.Equals(Button.BorderWidthProperty.PropertyName))

        {

            this.UpdateBackground();

        }

    }


    private void UpdateBackground()

    {

        if (this.TypedElement != null)

        {

            using (var background = new GradientDrawable())

            {

                background.SetColor(this.TypedElement.BackgroundColor.ToAndroid());

                background.SetStroke((int)Context.ToPixels(this.TypedElement.BorderWidth), this.TypedElement.BorderColor.ToAndroid());

                background.SetCornerRadius(Context.ToPixels(this.TypedElement.CornerRadius));


                // customize the button states as necessary

                using (var backgroundStates = new StateListDrawable())

                {

                    backgroundStates.AddState(new int[] { }, background);


                    this.Control.SetBackground(backgroundStates);

                }

            }

        }

    }

}

在上面的代碼中,背景是為所有狀態(tài)設(shè)置的,但可以自定義。例如,


// set a background for the un-pressed state

backgroundStates.AddState(new int[] { -Android.Resource.Attribute.StatePressed }, background);


// set a background for the pressed state

backgroundStates.AddState(new int[] { Android.Resource.Attribute.StatePressed }, backgroundPressed);



查看完整回答
反對(duì) 回復(fù) 2021-10-24
  • 1 回答
  • 0 關(guān)注
  • 166 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)