2014-09-23 4 views
1

Docant pdf 책의 공식 Android 자습서를 따르고 있습니다. 어떤 이유로 내 검색 아이콘이 나타나지 않습니다. holo_dark의 ic_action_search.png 사진과 dark action bar 테마의 홀로그램을 사용하는 im을 포함 시켰습니다.작업 표시 줄 검색 아이콘이 표시되지 않습니다.

: 여기 코드, 이클립스에서 찾을 수 없습니다하는 오류는 분 SDK는 내가이 줄, 당신의 오류가 onCreate method에 생각 (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> 

답변

0

로 설정되어있다 setContentView(textView);

콘텐츠 뷰를 텍스트 뷰가 아닌보기의 XML로 설정해야합니다.

같은 것을 보여야에서 onCreate :

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(the_name_of_your_xml_for_this_activity); 
    // 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); 
} 
+0

감사를 사용하는 것보다 당김 다른 방법으로 가져올 필요하지만 난이 XML 활동 오류 activity_display_message의 내 이름을 올려 놓을 때 해결 될 수없는 변수가 나타납니다 – brumbrum

+0

setContentView (R.layout.activity_display_message)로 시도하십시오 –

+0

나는 우리가 진전을 이루고 있다고 생각합니다! 감사! @ string/action_search의 제목을 오버플로에 넣습니다. 아직도 내 작업 표시 줄에 ic_action_search 아이콘이 없습니다. – brumbrum

0

은 내가 처음에 그것을 정의에 당신이 필요하다고 생각 고해상도/valuse/drawables.xml

<item name="ic_action_search" type="drawable">@android:drawable/ic_menu_search</item> 

검사 사진,

enter image description here

당신이 .bng 사진이있는 경우는

android:src="@drawable/ic_action_search" 
관련 문제