我正在尝试将一个按钮实现为一个片段,以便使用Float Action Button(FAB)来查看快餐栏。如何将fab1链接到片段中的按钮?这是.java
文件:
public class PrimaryFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.primary_layout,null);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab1);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Hai, Hallo", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
答案 0 :(得分:0)
试试这个:
getActivity().findViewById(R.id.fab1);