我無法在Android項目中添加ActionBarActivity。在我的任何項目中沒有appcpmpat-v7
的選項。如何在Android項目中添加ActionBarActivity?
我現在在做什麼?
我無法在Android項目中添加ActionBarActivity。在我的任何項目中沒有appcpmpat-v7
的選項。如何在Android項目中添加ActionBarActivity?
我現在在做什麼?
你應該在你的gradle這個文件com.android.support:appcompat-v7:21.0.0
依賴,並輸入了錯誤的問題類的名稱。
公共類MainActivity擴展活動{
@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);
}
}
如果這是一個基於項目的gradle那麼你可以添加在你的build.gradle文件中的以下的依賴,這將導入這種依賴性。
compile 'com.android.support:appcompat-v7:23.0.0'
PS:23.0.0是最新版本的Android瞄準M.您可以使用21或22,以及
您可以在這裏找到How to add suport library,ActionBarActivity and themes to android project? 答案如果您的工作區不包含程序兼容性,它會由Eclipse自動生成。
另外你需要實現「Actionbaractivity」 –