【问题标题】:Set a title for inflated view activity为膨胀的视图活动设置标题
【发布时间】:2017-08-15 07:32:16
【问题描述】:

My activity screenshot having red highlight area where i want to set title

我在我的活动中夸大了一个视图。我想为它设置一个标题,setTitlelabel 清单中的标签不起作用我已经尝试了数千次。 如何在屏幕截图的突出显示区域设置标题我的代码如下

 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);

【问题讨论】:

标签: android android-layout android-activity title layout-inflater


【解决方案1】:

如果要在应用栏的右上角设置标题,可以在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>

将此Toolbar 添加到顶部的Activity 布局中:activity_main.xml

【讨论】:

  • 它没有添加我想要的。它只是在工具栏@bob 下方添加一个文本视图
  • 您应该将此工具栏用作您的应用栏/操作栏。将此用作您的父主题:Theme.AppCompat.Light.NoActionBar。并将该工具栏设置为操作栏。
  • thnx @bob 我得到了答案。感谢您的努力
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多