ActionBarSherlock定制RelativeLayout的不显示标题文本 [英] ActionBarSherlock with custom RelativeLayout does not show title text

查看:161
本文介绍了ActionBarSherlock定制RelativeLayout的不显示标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在动作条不使用相对布局时显示的标题。 当我不使用RelativeLayout的,该项目不靠右侧。 请不要告诉我使用的菜单项作为解决方案。它必须是定制的。

The ActionBar does not show title when using relative layout. And when I not use the RelativeLayout, the items are not aligned to right. Please don't tell me to use menu items as the solution. It must be custom.

下面是我的设置:

    ActionBar bar = getSupportActionBar();
    bar.setDisplayOptions(
            ActionBar.DISPLAY_HOME_AS_UP |
            ActionBar.DISPLAY_SHOW_CUSTOM |
            ActionBar.DISPLAY_SHOW_HOME |
            ActionBar.DISPLAY_SHOW_TITLE |
            ActionBar.DISPLAY_USE_LOGO);

    bar.setTitle(title);
    bar.setCustomView(actionBar);
    this.setTitle(title);

这是当对齐是好的,但标题没有显示

This is when the align is good, but title is not shown

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true" >

        <ImageButton
            android:id="@+id/acion_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/menu_label_add"
            style="?attr/actionButtonStyle" />

        <ImageButton
            android:id="@+id/action_prev"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/menu_label_prev"
            style="?attr/actionButtonStyle" />

        <ImageButton
            android:id="@+id/action_next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/menu_label_next"
            style="?attr/actionButtonStyle" />

    </LinearLayout>

</RelativeLayout>

截图

这里来,其中的标题显示的布局,但项目是对齐到左

And here comes the layout where the title is shown, but the items are aligned to left

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:gravity="right">

    <ImageButton
        android:id="@+id/acion_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_label_add"
        style="?attr/actionButtonStyle" />

    <ImageButton
        android:id="@+id/action_prev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_label_prev"
        style="?attr/actionButtonStyle" />

    <ImageButton
        android:id="@+id/action_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_label_next"
        style="?attr/actionButtonStyle" />

</LinearLayout>

截图

推荐答案

我有同样的问题,发现此链接:<一href="https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0">https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0

I had the same problem and found this link: https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0

这为我工作:

布局:

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

    ...

</LinearLayout>

code:

code:

import com.actionbarsherlock.app.ActionBar.LayoutParams;
...
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
getSupportActionBar().setCustomView(segmentView, lp);

这篇关于ActionBarSherlock定制RelativeLayout的不显示标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆