android - 如何从 .java 文件启动画面访问 Monodroid 资源

标签 android android-layout resources xamarin.android

我正在尝试在 Visual Studio 的 Monodroid 应用程序中实现 .java 启动画面,无论如何我希望启动画面从资源布局中获取它的内容 View 。我试图像这样得到它:

setContentView(R.layout.AppSplash);

也试过:

setContentView(Resource.layout.AppSplash);

还有:

setContentView("@layout/AppSplash");

我收到这样的错误消息:

package R does not exist

R 因资源而改变或:

cannot find symbol
symbol  : method setContentView(java.lang.String)
location: class SwimmerTimesCalc.SplashActivity
    setContentView("@layout/AppSplash");

当我尝试@layout/AppSplash 选项时

如何访问 Monodroid 资源来设置启动画面的布局?

最佳答案

This应该可以帮助您入门。

如果您想使用专门用于创建您自己的初始屏幕的布局,然后使用该资源在您的 Activity 中显示它,那么您可以使用类似这样的东西。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/SplashScreenLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<ImageView
    android:id="@+id/SplashDefault"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:scaleType="centerCrop" />
</RelativeLayout>

然后在您的 Activity 中,您只需设置内容 View 即可。

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.SplashLayout);
    }

关于android - 如何从 .java 文件启动画面访问 Monodroid 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005296/

相关文章:

android - 使用自签名证书在 chrome android 上远程调试服务 worker

android - 如何在android中的RecyclerView中填充数据?

Android Material Design AppBarLayout 的属性layout_scrollFlags 有问题

maven-2 - Junit 运行时不选择文件 src/test/resources。对于某些依赖 jar 所需的文件

Java - 如果用户意外关闭程序,try-with-resources 会调用 .close() 吗?

c# - 如何在 Visual Studio 中的项目之间共享资源文件?

Android——对象创建/内存分配与性能

android - 打开 .xml 文件后 Eclipse 崩溃

android - 在我的 kotlin/android 代码中,联系人姓名未显示在收件箱中

java - 如何创建可扩展的表单?