海底导航SS我已经用android在我的应用程序中做了底部导航。所以,我想在我的一个片段中创建一个按钮。我该怎么做呢?有视频参考资料吗?谢谢。
发布于 2018-05-24 04:51:01
这很容易,也不太难,只需将按钮放在片段布局中,然后在片段中创建实例之后,将侦听器放置到特定按钮中,如以下所示。
<?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
}
});
}
}https://stackoverflow.com/questions/50500822
复制相似问题