我想在工具栏中使用自定义文本而不是App Name
我在xml
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:elevation="20dp">
<TextView
android:id="@+id/toolbartitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="my toolbar"/>
</android.support.v7.widget.Toolbar>
并使用此
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
TextView mytext=findViewById(R.id.toolbartitle);
setSupportActionBar(toolbar);
MainActivity中的但它显示像这样
MyApp的
我如何纠正它才能显示我的文字?
答案 0 :(得分:1)
试试这个,
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
TextView mytext=findViewById(R.id.toolbartitle);
setSupportActionBar(toolbar);
getSupprotActionBar().setTitle(" "); // impotent
更新:
或者您可以在清单文件
中执行此操作<activity
android:name=".SelectionActivity"
android:label="" <!-- impotent -->
android:screenOrientation="portrait" />
快乐编码。
答案 1 :(得分:1)
试试这个
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setTitle("");
toolbar.setSubtitle("");
setDisplayShowTitleEnabled
可帮助您从工具栏中停用标题。
答案 2 :(得分:0)
删除TextView
内的Toolbar
,您不需要。{/ p>
将此行添加到Toolbar
定义
app:title="@string/app_name"