【问题标题】:application name center alignment in android`android`中的应用程序名称中心对齐
【发布时间】:2012-02-04 18:17:28
【问题描述】:

我可以在android中将应用程序名称居中对齐吗

默认情况下,应用程序名称在左侧对齐。

那么如何让它居中对齐

【问题讨论】:

    标签: java android eclipse


    【解决方案1】:

    如果它不起作用,请将您的布局和 textview 重力设置为中心,然后尝试将 textview layoutGravity 设置为中心

    【讨论】:

      【解决方案2】:

      你会在 xml 中尝试这个

      android:layout_centerhorizontal="true"
      

      【讨论】:

      • 你能说我必须在哪个 XML 文件中使用上面的代码。我也在努力解决同样的问题。
      • 我的标题栏上的应用程序标题默认是左对齐的,我想让它居中。不是任何文本视图或其他。
      • 我正在发布与新问题相同的内容,我会在那里明确说明。
      • 我在android:layout_ 中没有centerhorizontal 的选项.. 如何进行?
      • 需要知道在哪里应用这个属性。
      【解决方案3】:

      您必须创建一个自定义主题并设置窗口标题的样式以满足您的需要。
      这有一些指导方针http://labs.makemachine.net/2010/03/custom-android-window-title/

      您也可以使用 FEATURE_CUSTOM_TITLE 并相应地设置格式。 这里详细介绍了这种方法。
      How to change the text on the action bar

      【讨论】:

        【解决方案4】:

        要在您的 Toolbar 中使用自定义标题,您只需记住 Toolbar 只是一个 精美的 ViewGroup,因此您可以像这样添加自定义标题:

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_top"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:background="@color/action_bar_bkgnd"
            app:theme="@style/ToolBarTheme" >
        
        
             <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Toolbar Title"
                android:layout_gravity="center"
                android:id="@+id/toolbar_title" />
        
        
            </android.support.v7.widget.Toolbar>

        这意味着您可以随意设置 TextView 的样式,因为它只是一个常规的 TextView。因此,在您的活动中,您可以像这样访问标题:

        Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
        TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
        

        【讨论】:

          【解决方案5】:

          您必须更改 manifests 中的主题,它实际上在 android 开发者网站中得到了很好的解释...查看此链接 https://developer.android.com/training/appbar/setting-up#java

          【讨论】:

          • 缺少所需的代码示例以及此潜在解决方案适用于哪个版本。
          猜你喜欢
          • 2015-07-21
          • 1970-01-01
          • 2011-05-08
          • 2018-02-20
          • 2012-04-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多