gpt4 book ai didi

安卓工具栏标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:10 26 4
gpt4 key购买 nike

无法更改工具栏标题 我在 manifeast.xml 中设置了标题并且还使用了 setTitle("TITLE");

我将标题设置为 History & Reports 但它显示不同的标题 Notifications 这是另一个 Activity 标题。

我检查了 manifeast.xml 但没有变化,任何人都可以帮助我解决这个问题。

这是我的代码

public class Nav_HistoryAndReports extends AppCompatActivity {

private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("History & Reports");
setContentView(R.layout.nav_history_and_reports);

toolbar = (Toolbar) findViewById(R.id.toolbar);
setToolbar(toolbar);

viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);

tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}

public void setToolbar(Toolbar toolbar) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new FragmentHistoryAndReports_Visits(), "VISITS");
adapter.addFragment(new FragmentHistoryAndReports_Visitors(), "VISITORS");
adapter.addFragment(new FragmentHistoryAndReports_Map(), "MAP");
viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}

@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}

@Override
public int getCount() {
return mFragmentList.size();
}

public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}

@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@color/white"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:titleTextColor="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIcon="?attr/homeAsUpIndicator"
app:theme="@style/GalaxyZooThemeToolbarDarkOverflow">

</android.support.v7.widget.Toolbar>

最佳答案

Toolbar Title可以通过两种方式设置

1.在布局 XML 中

<android.support.design.widget.AppBarLayout

android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:elevation="4dp"
android:theme="@style/AppTheme.AppBarOverlay"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:title="Main Activity"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:navigationIcon="@drawable/ic_arrow_back_white_24dp"

app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<强>2。在Java中它将在 AppCompatActivity 中工作

Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Notice Board");
setSupportActionBar(toolbar);

关于安卓工具栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42919123/

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