This Question have 1 answers right now.

Custom Actionbar layout not showing

Question!

Hey guys I'm trying to implement a search view but my actionbar does not display the things I want. It's just empty. Here is my activity code

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    setContentView(R.layout.search_tag);
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    actionBar.setCustomView(R.layout.searchview);
    actionBar.setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM | android.support.v7.app.ActionBar.DISPLAY_SHOW_HOME);

}

My activity extends AppCompatActivity, just mentioning that to avoid confusion. Here is my searchview:

 <?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:theme="@style/Theme.MyTheme">

    <EditText xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/searchfield"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/transparent"
        android:imeOptions="actionGo"
        android:inputType="textWebEmailAddress"
        android:text="www.google.com" />


</LinearLayout>

The main layout for the activity is just an empty linear layout. I think I'm missing something. Anyone has an idea what is wrong with the code?

Thanks in advance



Answers

You calling setContentView and then working on the view later. Try moving the actionbar code before the setContentView method is called.

By : fzxt


Video about Custom Actionbar layout not showing