Tôi đang bắt đầu phát triển một ứng dụng mới và tôi triying để cung cấp cho nó một cái nhìn thiết kế material design. Đối với điều này, tôi đang sử dụng khả năng tương thích hỗ trợ v7.Ẩn tiêu đề ứng dụng trên support.v7.widget.toolbar
Trong một số hoạt động của ứng dụng, tôi cần thanh công cụ không hiển thị tiêu đề ứng dụng, tôi không biết cách thực hiện, nhưng nó được hiển thị theo mặc định. Trong những hoạt động đó, tôi có một bản xem văn bản ở bên phải của thanh công cụ hoạt động như một nút và nơi tôi đã triển khai RippleEffect của traex.
Vì vậy, về cơ bản câu hỏi của tôi là, làm cách nào để ẩn tiêu đề của ứng dụng khỏi thanh công cụ? Bởi vì ngay cả khi tôi làm:
toolbar.setTitle("");
hoặc
toolbar.setTitle(null);
nó tiếp tục xuất hiện.
Đây là mã của tôi:
Tuỳ chỉnh thanh công cụ xml [toolbar_intro.xml]:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:ripple="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<com.andexert.library.RippleView
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="40dp"
ripple:rv_centered="false"
app:rv_rippleDuration="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toolbar_text"
android:textColor="@color/White"
android:textStyle="bold"
android:textSize="25sp"
android:text="Next"/>
</com.andexert.library.RippleView>
</android.support.v7.widget.Toolbar>
Đây là cách tôi bao gồm các thanh công cụ trong cách bố trí:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_intro" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
...
</RelativeLayout>
</LinearLayout>
Và đây là hoạt động:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intro_wellcome);
toolbar= (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setTitle("");
}
TextView toolbar_text = (TextView) toolbar.findViewById(R.id.toolbar_text);
toolbar_text.setText(R.string.next);
...
}
Ngoài ra, đây là phong cách mà tôi đã thực hiện:
<style name="MaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
Đơn giản như vậy! Cảm ơn! – masmic
Không sao cả. Hãy chắc chắn rằng bạn kiểm tra nullpointer để tránh cảnh báo :) –
bạn có thể thử như toolbar.setTitle (""); –