먼저, 비슷한 문제를 처리하는 많은 SO가 있음을 알고 있습니다. 나는 그들 모두를 샅샅이 뒤졌고, 제공된 답 중 어느 것도 내 문제를 해결하는 데 도움이되지 못했습니다.Android ActionBar에 코드에 설정된 제목이 표시되지 않습니다.
내 android.support.v7.widget.Toolbar
구성 요소에 제목 (또는 뒤로 버튼)을 표시 할 수 없습니다. 내가 뭘했는지 상관없이.
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="infos" type="com.mycompany.orm.adapters.ListViewAdapter"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/buttonBackground"
android:elevation="4dp"
android:logo="@drawable/ic_close_white_24dp" />
<ListView
android:id="@+id/my_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/windowBackground"
bind:items="@{infos.list}"/>
</RelativeLayout>
</layout>
그리고 (MyActivity.java)로 활동 onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
if (toolbar != null) {
toolbar.setTitle("My Name Here"); // Never shows up
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setTitle("Hello World!"); // Never shows up
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.show();
}
}
}
그러나 사용
나는 그 ( my_activity.xml)처럼 보이는 안드로이드 활동을 이 코드에서는 빈 툴바 만 볼 수 있습니다. 텍스트 (My Name Here
또는
Hello World!
)를 볼 수는 없지만,
bind:title="Testing"
을 XML의
Toolbar
요소에 추가하면
이라는 제목으로 표시됩니다. 그러나의 모양을 조작하고 싶습니다. 도구 모음/액션 바는, 그래서 코드에서 그것을 할 수 있도록하고 싶습니다.
사람이 내가 같은 문제에 직면했고이 나를 위해 일한?
위와 동일해야합니까? 'ActionBar actionBar = getSupportActionBar(); if (actionBar! = null) {actionBar.setTitle ("Hello World!"); }' – Brett
다음 테마를 사용하고 있습니까? <응용 프로그램 android : theme = "@ style/Theme.AppCompat.Light.NoActionBar" /> – John
@ 브렛 : 동일한 XML과 코드를 사용하여 "Hello world!" com.android.support:appcompat-v7 23.0.0, – John