Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getActionBar().setTitle does not work

ActionBar - setTitle seems to not to be called. All other things I'm doing with ActionBar (like HomeIsUp and so on) are going well, but setTitle - not.

Here is the code of a simple activity:

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
}
}

Why does it not set the title?

in manifest:

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

in layout:

<?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>
like image 630
Ivan Fazaniuk Avatar asked Sep 25 '14 18:09

Ivan Fazaniuk


People also ask

How to add icons in Action Bar in Android?

To generate ActionBar icons, be sure to use the Asset Studio in Android Studio. To create a new Android icon set, right click on a res/drawable folder and invoke New -> Image Asset.

How to set Action Bar in Android Studio?

To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.

What is appbar in Android?

The app bar, also known as the action bar, is one of the most important design elements in your app's activities, because it provides a visual structure and interactive elements that are familiar to users.


1 Answers

because of

getActionBar().setDisplayShowTitleEnabled(false);

change it to

getActionBar().setDisplayShowTitleEnabled(true);
like image 130
mmlooloo Avatar answered Oct 27 '22 23:10

mmlooloo