【发布时间】:2021-10-17 04:44:00
【问题描述】:
@ColeX - MSFT 帮助了 Xamarin 项目中的 implementation of SpotLight。
-
现在,我希望当应用第一次打开时,这个聚光灯应该启动 自动(android 页面)。
-
当它关闭时,应该会出现表单页面。我的意思是,我如何检测所有(3)个聚光灯是否都消失了?这样我就可以导航到表单页面,该页面将具有我想要显示的实际 UI。
页面的自定义渲染器。
[assembly: ExportRenderer(typeof(Page1), typeof(MainPageRenderer))]
namespace CustomRenderer.Droid
{
class MainPageRenderer : PageRenderer
{
private Android.Views.View view;
private Android.Widget.Button button1;
private Android.Widget.Button button2;
private Android.Widget.Button button3;
public MainPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
view = MainActivity.Instance.LayoutInflater.Inflate(Resource.Layout.MyPage, this, false);
AddView(view);
view.Click += View_Click;
button1 = view.FindViewById<Android.Widget.Button>(Resource.Id.firstButton);
button2 = view.FindViewById<Android.Widget.Button>(Resource.Id.secondButton);
button3 = view.FindViewById<Android.Widget.Button>(Resource.Id.thirdButton);
}
bool isShown_FirstButton_SpotLight = false;
bool isShown_SecondButton_SpotLight = false;
bool isShown_ThirdButton_SpotLight = false;
private void View_Click(object sender, EventArgs e)
{
if (!isShown_FirstButton_SpotLight)
{
show(button1 ,"First Button" ,"Lorem ipsum dolor sit amet, consectetur adipiscing elit", "FirstButton");
isShown_FirstButton_SpotLight = true;
return;
}
if (!isShown_SecondButton_SpotLight)
{
show(button2,"Second Button", "Sed do eiusmod tempor incididunt ut labore eta", "SecondButton");
isShown_SecondButton_SpotLight = true;
return;
}
if (!isShown_ThirdButton_SpotLight)
{
show(button3,"Third Button", "Ut enim ad minim veniam, quis nostrud exercitation", "ThirdButton");
isShown_ThirdButton_SpotLight = true;
return;
}
}
void show(Android.Views.View view, string title, string subTitle, string usageId)
{
new SpotlightView.Builder(MainActivity.Instance)
.IntroAnimationDuration(400)
.EnableRevealAnimation(true)
.PerformClick(true)
.FadeinTextDuration(400)
.HeadingTvColor(Android.Graphics.Color.ParseColor("#eb273f"))
.HeadingTvSize(32)
.HeadingTvText(title)
.SubHeadingTvColor(Android.Graphics.Color.ParseColor("#eb273f"))
.SubHeadingTvSize(16)
.SubHeadingTvText(subTitle)
.MaskColor(Android.Graphics.Color.ParseColor("#dc000000"))
.Target(view)
.LineAnimDuration(400)
.LineAndArcColor(Android.Graphics.Color.ParseColor("#eb273f"))
.DismissOnTouch(true)
.DismissOnBackPress(true)
.EnableDismissAfterShown(true)
.UsageId(usageId)
.ShowTargetArc(true)
.Show();
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);
view.Measure(msw, msh);
view.Layout(0, 0, r - l, b - t);
}
}
}
资源/布局/我的页面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/firstButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:text="First"
android:background="#00ff00"/>
<Button
android:id="@+id/secondButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp"
android:text="Second"
android:background="#ff0000"/>
<Button
android:id="@+id/thirdButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="150dp"
android:text="Third"
android:background="#0000ff"/>
</LinearLayout>
【问题讨论】:
标签: c# .net xamarin xamarin.forms