我正在尝试将 FloatingActionButton 添加到 FloatingActionMenu 但是在 FloatingActionButton 初始化期间无法获取上下文时,所有方法都返回 null
这是我的片段调用
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import demo.com.example.syed.test.R;
public class stdDetails extends android.support.v4.app.Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FloatingActionMenu detailsfabmenu=(FloatingActionMenu)Container.findViewById(R,id,std_Main_Detials_fab_menu);
FoatingActionButton(getContext());
detailsfabmenu.addButton(changename);
return inflater.inflate(R.layout.stddetailsfragment,container,false);
}}
代码
FloatingActionButton changename=new FloatingActionButton(getContext());
返回空值我什至尝试过基于 avilabel 答案的以下选项
FloatingActionButton changename=new FloatingActionButton(container.getContext());
FloatingActionButton changename=new FloatingActionButton(getActivity().getApplicationContext());
FloatingActionButton changename=new FloatingActionButton(this.getContext());
FloatingActionButton changename=new FloatingActionButton(this.getActivity().getApplicationContext());
这是此处提供的所有答案 在片段中使用上下文