【问题标题】:Create button in actionbar with text on it [duplicate]在操作栏中创建带有文本的按钮[重复]
【发布时间】:2018-02-11 09:17:06
【问题描述】:

目前我正在像这样在我的应用程序中显示分数。但是我想给这个文本一些物质效果或背景,以改善外观和感觉。我想要这样的东西,有可能实现吗?

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/scorePointsText"
        android:title="@string/scorePoints"
        app:showAsAction="always" />
    <item
        android:id="@+id/scoreBoard"
        android:icon="@drawable/main_score"
        android:title="@string/scorePoints"
        app:showAsAction="always" />
</menu> 

我使用上面的代码为操作栏充气。

【问题讨论】:

  • 我只是举了一个例子,它可以是循环的。我真正想要的是为这篇文章提供一些背景知识,以改善乐谱的外观和感觉。
  • 好的,我已经描述了这个问题。我对安卓很陌生。如果这个问题浪费了您的时间,我很抱歉。

标签: android


【解决方案1】:

你可以在ImageView上添加一个圆形的TextView并放入AppBarLayout。及上方的工具栏。 像这样:

<android.support.design.widget.AppBarLayout
        android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textView"
            android:text="5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/Image_view"
            android:src="@drawable/circule"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_single_poem"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways" />

    </android.support.design.widget.AppBarLayout>

【讨论】:

    【解决方案2】:

    尝试像这样实现工具栏

     <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_single_poem"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways" >
    
          <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text = "5"
                android:layout_gravity = "right"
                android:background = "@drawable/circle"/>
    </android.support.v7.widget.Toolbar>
    

    【讨论】:

    • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    猜你喜欢
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多