0
以下のコードを使用してApi-11でActionBarを作成しても問題ありませんが、別のApi-11プロジェクトで使用する場合は、デバイスでアプリケーションを実行すると強制終了します。問題はどこだ?ActionBarの問題
新しいプロジェクトを作成し、コンパイルしてアンドロイドデバイスでアプリを実行すると、正常に動作します。
package a.pkg;
import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class ActionBarActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar=getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#fc0606")));
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
//TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
//mTitleTextView.setText("My Own Title");
final ImageButton imageButton1 = (ImageButton) mCustomView
.findViewById(R.id.ImageButton1);
imageButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "1",
Toast.LENGTH_LONG).show();
}
});
final ImageButton imageButton2 = (ImageButton) mCustomView
.findViewById(R.id.ImageButton2);
imageButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "2",
Toast.LENGTH_LONG).show();
}
});
final ImageButton imageButton3 = (ImageButton) mCustomView
.findViewById(R.id.ImageButton3);
imageButton3.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "3",
Toast.LENGTH_LONG).show();
}
});
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
}
}