gpt4 book ai didi

java - Android 删除操作栏标题保留工具栏菜单

转载 作者:行者123 更新时间:2023-12-01 07:03:38 26 4
gpt4 key购买 nike

我需要将选项卡式工具栏保留在应用程序中,并删除操作栏。现在是这样的: enter image description here

但我希望它看起来像这样:

enter image description here

我的代码 xml 是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"/>

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

这是我的 .java:

public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

if (toolbar != null) {
setSupportActionBar(toolbar);
}

viewPager.setAdapter(new SectionPagerAdapter(getSupportFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
}

public class SectionPagerAdapter extends FragmentPagerAdapter {

public SectionPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new myFragment1();
case 1:
default:
return new myFragment2();
}
}

@Override
public int getCount() {
return 2;
}

@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "myfragment1";
case 1:
default:
return "myfragment2";
}
}
}


}

我怎样才能实现它?谢谢指教

最佳答案

只需将其添加到您的 MainActivity 中,这将隐藏工具栏的文本

getSupportActionBar().setTitle("");

要删除工具栏,您可以将其可见性设置为消失

android:visibility="gone"

关于java - Android 删除操作栏标题保留工具栏菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33692388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com