Android getActionBar().setTitle不起作用

Android getActionBar().setTitle不起作用,android,android-actionbar,Android,Android Actionbar,ActionBar-setTitle似乎没有被调用。我用ActionBar做的所有其他事情(比如HomeIsUp等等)都进展顺利,但setTitle——不是 以下是一个简单活动的代码: public class GuidelineDetails extends Activity implements OnClickListener { String guideline_name; String guideline_attachment; public static T

ActionBar-setTitle似乎没有被调用。我用ActionBar做的所有其他事情(比如HomeIsUp等等)都进展顺利,但setTitle——不是

以下是一个简单活动的代码:

public class GuidelineDetails extends Activity implements OnClickListener {

    String guideline_name;
    String guideline_attachment;

    public static TextView tv_title;
    public static TextView tv_intro;
    public static TextView tv_test;
    public static WebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.guideline_detail);
        getActionBar().setTitle("Privet");
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setIcon(R.drawable.listbullet);

///// some code
}
}
为什么不设置标题?

在舱单中:

<activity
            android:name=".GuidelineDetails"
            android:configChanges="orientation"
            android:label="Guideline"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Holo.Light" >
        </activity>
    <activity android:name=".MessagingActivity"
        android:label="MessagingActivity"
        android:parentActivityName=".LoginActivity"
        android:theme="@style/AppTheme.NoActionBar"></activity>

在布局中:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/guideline_title"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="1dp"
                    android:paddingLeft="10dp"
                    android:paddingRight="1dp"
                    android:paddingTop="35dp"
                    android:textSize="18dp"
                    android:textStyle="bold" />
            </TableRow>

        </TableLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.16"
        android:orientation="vertical" >     

         <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

          <WebView
    android:id="@+id/webviewD"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
/>

        </TableRow>



    </LinearLayout>

</LinearLayout>


您是否尝试设置字幕?因为在某些情况下,如果ActionBar中的设备屏幕很小,则只能看到ActionBar图标。试试这个.getActionBar().setTitle(“女贞”);希望这对你有帮助

我想这是因为清单文件控制了它。我的图标也有同样的问题,所以我只需在清单文件中更改它(
android:label=“Guideline”
),或者如果必须按语法设置,请尝试不在清单中设置标签

尝试扩展ActionBarActivity而不是Activity

因为

getActionBar().setDisplayShowTitleEnabled(false);
换成

getActionBar().setDisplayShowTitleEnabled(true);
在舱单中:

<activity
            android:name=".GuidelineDetails"
            android:configChanges="orientation"
            android:label="Guideline"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Holo.Light" >
        </activity>
    <activity android:name=".MessagingActivity"
        android:label="MessagingActivity"
        android:parentActivityName=".LoginActivity"
        android:theme="@style/AppTheme.NoActionBar"></activity>
以及xml:

<?xml version="1.0" encoding="utf-8"?>                                                            <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MessagingActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:layout_constraintTop_toTopOf="parent"
    >

    <include layout="@layout/toolbar_messaging" />


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


那么您想设置什么标题“指南”或“女贞”?相应地,在清单中或通过
onCreate
中的代码进行设置。所以决定并做吧one@ShobhitPuri已删除的语句android:label=“Guideline”但仍然不起作用:(是,因为您已经设置了
setDisplayShowTitleEnabled(false)
。请尝试将其设置为真。感谢您的建议,但它没有帮助:(从清单中删除此项。1)您的代码与我的代码没有任何不同。2)已尝试设置Sublite-也不起作用。不适用于我:getSupportActionBar().setDisplayShowTitleEnabled(true);getSupportActionBar().setTitle(R.string.action\u bar\u title)@你有没有找到解决问题的办法?setDisplayShowTitleEnabled(true)也不适用于我。