无法在Android中的片段中设置标题

问题描述 投票:0回答:1

我正在使用Android中的默认导航抽屉。我想根据抽屉中单击的片段来更改操作栏的标题。为此,我在代码中写以下行:

getActivity().getActionBar().setTitle("Coupons");

这将返回空对象。所以我尝试使用下面的代码行:

getActivity().getSupportActionBar().setTitle("Coupons");

这无法解析方法supportActionBar()。活动是AppCompatActivity。

android android-actionbar title
1个回答
0
投票

所有标题和字符串都放置在android studio中的strings.xml文件中。打开strings.xml并将现有文本更改为“ Coupons”。

strings.xml位于项目视图中的此处。Strings.xml location in Android Studio

© www.soinside.com 2019 - 2024. All rights reserved.