我從以下PDF Docant書官方Android教程。出於某種原因,我的搜索圖標不會顯示出來。我包括來自holo_dark的ic_action_search.png照片,以及使用全暗光與黑暗動作欄主題的即時通訊。 下面是代碼,沒有被蝕發現錯誤回報,最小SDK是設置爲11在操作欄搜索圖標不會出現
DisplayMessageActivity.java文件
package com.example.myfirstapp1;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayMessageActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="always" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
感謝,但,當我把這個XML活動錯誤activity_display_message的我的名字不能被解析爲一個變量出現 – brumbrum 2014-09-23 19:42:58
嘗試setContentView(R.layout.activity_display_message) – 2014-09-23 19:45:24
我認爲我們正在取得進展!謝謝!它將@ string/action_search後面的標題放入了溢出。我的操作欄中仍然沒有ic_action_search圖標。 – brumbrum 2014-09-23 20:00:25