【问题标题】:Headers in Activity活动中的标题
【发布时间】:2016-12-08 08:00:02
【问题描述】:

我是 Android 新手。我想在活动的顶部放一个标题,类似于 iOS 中的 UINavigationBar。我需要在标题的左侧放置一个图标和一个标题(文本或带有徽标和标题的图像)。请找到图片链接以了解我想要的标题。

https://www.dropbox.com/s/onsc3klzc0bafia/Screen%20Shot%202016-12-08%20at%201.00.13%20PM.png?dl=0

【问题讨论】:

标签: java android android-activity


【解决方案1】:

在你的 xml 中使用这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<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="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

然后在活动中 onCreate();添加这个

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_toolbar);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("YOUR_TITLE");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

此行将在工具栏的左角添加箭头

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多