Bottom navigation SS我已经使用android studio在我的应用程序中完成了底部导航。所以,我想在我的一个片段中创建一个按钮。我该怎么做?任何视频参考?谢谢。
答案 0 :(得分:1)
只需将按钮放入片段布局,然后在片段中创建实例并将该特定按钮的监听器放在下面即可,这样就不那么容易了。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatButton
android:id="@+id/mBtnPresent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
@SuppressLint("ValidFragment")
public class FragmentTest extends Fragment {
private View view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_test, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppCompatButton mBtnPresent=view.findViewById(R.id.mBtnPresent);
mBtnPresent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//perform action what you want on button click
}
});
}
}