我无法在我的安卓项目中添加ActionBarActivity。在我的任何项目中都没有appcpmpat-v7的选项。
我现在该怎么做?
发布于 2015-08-31 20:09:10
公共类MainActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
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");
ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onCl`enter code here`ick(View view) {
Toast.makeText(getApplication`enter code here`Context(), "Refresh Clicked!",
Toast.LENGTH_LONG).show();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}}
发布于 2015-08-31 20:09:24
如果这是一个基于gradle的项目,那么您可以在您的build.gradle文件中添加以下依赖项,该文件将导入此依赖项。
compile 'com.android.support:appcompat-v7:23.0.0'PS: 23.0.0是针对android M的最新版本。您也可以使用21或22
发布于 2015-08-31 20:06:20
您应该在gradle文件中具有对com.android.support:appcompat-v7:21.0.0的依赖关系
而且你输入了错误的类名。
https://stackoverflow.com/questions/32310681
复制相似问题