簡體   English   中英

自定義操作欄布局未顯示

[英]Custom Actionbar layout not showing

大家好,我正在嘗試實現搜索視圖,但是我的操作欄沒有顯示我想要的東西。 它只是空的。 這是我的活動代碼

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);

}

我的活動擴展了AppCompatActivity,只是提到了避免混淆。 這是我的搜索視圖:

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

活動的主要布局只是一個空的線性布局。 我想我缺少了一些東西。 任何人都知道代碼有什么問題嗎?

提前致謝

您調用setContentView ,然后在以后處理視圖。 在調用setContentView方法之前,請嘗試移動操作欄代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM