如何在片段内部使用Compose?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在片段内部使用Compose?相关的知识,希望对你有一定的参考价值。

该文档介绍了如何在Activity中创建UI。但是如何在片段中使用它?

答案

您可以在片段中创建onCreateView,然后定义所有

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup  container, @Nullable Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    final View view = inflater.inflate(R.layout.fragment_layout, container, false);

//You can define your code here
 //same like activity
//but use view. before findViewById it will work fine
    button= view.findViewById(R.id.button); 

    getData();

    return view;

}

以上是关于如何在片段内部使用Compose?的主要内容,如果未能解决你的问题,请参考以下文章