首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActionBar问题

ActionBar问题
EN

Stack Overflow用户
提问于 2016-06-28 15:50:01
回答 1查看 13关注 0票数 0

我使用下面的代码在Api-11下创建ActionBar,它工作得很好,但当我想在另一个Api-11项目中使用它时,当我在我的设备上运行应用程序时,会发生强制关闭。问题出在哪里?

当我创建一个新的项目,编译它并在android设备上运行应用程序时,它工作得很好!

代码语言:javascript
复制
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);

    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-06-28 17:37:21

我发现了这个问题,我必须在清单中手动将代码从这个更改为这个。eclipse无法自动将最小Api从8更改为11。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38070201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档