具有两行文本的操作栏

问题描述 投票:0回答:1

我如何用两行来制作这种动作栏?第二行在类内部定义了一个图标和一个可变文本。

enter image description here

android android-actionbar
1个回答
0
投票

您可以在操作栏中添加两行,例如“标题”和“副标题”。为此,您需要设置DISPLAY_SHOW_TITLE

我将为此建议两个资源。 example of setDisplayOptions implementationofficial doc

您也可以使用这些代码作为参考,

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="Android Actionbar Title and SubTitle Example"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Android action bar title and subtitle tutorial with example. learn 
        to add subtitle in android actionbar" />


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:autoLink="web"
        android:gravity="center|bottom"
        android:text="ViralAndroid.com"
        android:textSize="24sp"
        android:textStyle="bold" />
</LinearLayout>

JAVA:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionbar_title_and_subtitle);

android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("ActionBar Title");
actionBar.setSubtitle(Html.fromHtml("<font color='#FFBF00'>Here ActionBar 
Subtitle</font>"));
}

对于图标,您可以遵循this

© www.soinside.com 2019 - 2024. All rights reserved.