[英]Set a title for inflated view activity
我在活動中添加了一個視圖,我想為其設置標題,清單中的setTitle
和label
標簽不起作用,我已經嘗試了數千次。 如何在屏幕截圖的突出顯示區域中設置標題,我的代碼如下
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameHome);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View inflate = layoutInflater.inflate(R.layout.activity_main, null, true);
frameLayout.addView(inflate);
如果您想在應用欄的右上角設置標題,則可以在Toolbar
放置一個TextView
。
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Your Title"
android:layout_gravity="end"/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
在頂部的“ Activity
布局中添加此Toolbar
: activity_main.xml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.