问题描述
我正在尝试在 Android Studio 中创建一个应用程序,在该应用程序中,用户可以在单击按钮时创建新选项卡……就像 chrome,但不同之处在于它们应该是永久性的,与 chrome 选项卡不同,并且只能由用户在另一个按钮上删除单击,我想让这些新选项卡可自定义,以便用户也可以在其中添加新项目。 到目前为止,我已经使用选项卡布局制作了 XML 布局并添加了已删除的按钮,但我是 android 开发的新手,我不知道下一步该做什么,我学会了通过添加新片段来静态添加选项卡,但我不知道如何使其动态,以便用户可以添加/删除新 tabs.plz,任何帮助表示赞赏...
.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TableLayout;
public class MainActivity extends AppCompatActivity {
TableLayout tableLayout;
Button button;
ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tableLayout.findViewById(R.id.tablayout);
button.findViewById(R.id.button1);
viewPager.findViewById(R.id.viewpager);
}
}
.Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add routine"
/>
</LinearLayout>
</LinearLayout>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)