在我的主FragmentActivity菜单中,我设置了这样的自定义ActionBar标题:
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.custom_titlebar, null);
TextView tv = (TextView) v.findViewById(R.id.title);
Typeface tf = Typeface.createFromAsset(this.getAssets(),
"fonts/capsuula.ttf");
tv.setTypeface(tf);
tv.setText(this.getTitle());
actionBar.setCustomView(v);
Run Code Online (Sandbox Code Playgroud)
这很完美.但是,一旦我打开其他Fragments,我希望标题改变.我不知道如何访问Main Activity来做到这一点?在过去,我这样做了:
((MainFragmentActivity) getActivity()).getSupportActionBar().setTitle(
catTitle);
Run Code Online (Sandbox Code Playgroud)
有人可以就正确的方法提出建议吗?
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:ellipsize="end"
android:maxLines="1"
android:text=""
android:textColor="#fff"
android:textSize="25sp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) android android-fragments android-actionbar android-fragmentactivity
我正在尝试在 Android 中使用导航控制器
如上图所示,我将label目的地的属性设置为“Home”。
这个标签将在我的工具栏中显示类似标题。我可以以编程方式更改该标签吗?因为我想动态设置工具栏标题。
我尝试使用更改工具栏标题,toolbar.title = "some title here"但它始终会与该标签的标题重叠。
那么如何解决这个问题呢?