我无法使用 android studio 编辑我的 android 电视应用程序的设计

I can't edit the design of my android tv application with android studio

我正在为 android 电视创建一个新项目。 我没有书面代码。 我无法修改应用程序的设计

error message: unknown fragment

错误的更多详细信息:

A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout.

错误图片

xml代码:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_browse_fragment"
    android:name="com.example.milchycompany.myapplication.MainFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:deviceIds="tv"
    tools:ignore="MergeRootFrame" />

代码 MainActivity

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

请帮忙创建我的第一个 android 电视应用程序

我猜您的 com.example.milchycompany.myapplication.MainFragment 是从 BrowseFragment 扩展而来的。该 Fragment 动态包含作为 Leanback 库一部分的布局,例如 R.layout.lb_browse_fragment 以及以编程方式生成其他布局的适配器。因此,它不是为在布局编辑器中进行编辑而设计的。相反,您会调用各种设置器来调整 UI,例如

setTitle(getString(R.string.browse_title));

setBrandColor(ContextCompat.getColor(requireContext(), R.color.your_brand_color));

如果您的 MainFragment 不是从 BrowseFragment 扩展的,那么您应该打开它并查看在其 onCreateView 方法中设置的布局,然后修改该布局。