[英]Make home icon clickable on the action bar, under api level 14
我目前正在使用getActionBar().setHomeButtonEnabled(true);
它工作正常,但需要api級別14,沒有它,我將能夠一直下降到api 8,這太棒了! 如果有人知道解決方法,請告訴我。
您必須使用支持庫,並且代碼將如下所示:
import android.support.v7.app.ActionBar
public class YourActivity extends ActionBarActivity {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getSupportActionBar(); // now do whatever you want to do with this action bar
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// code for your action when you click home icon on action bar
break;
default:
break;
}
return true;
}
}
只需使用ActionBarSherlock或ActionBarCompat即可 。 這些將處理低API級別,並自動將本機ActionBar用於較高的API。
您可以使用ActionBar
支持庫: http : //developer.android.com/guide/topics/ui/actionbar.html
代替getActionBar()
,使用getSupportActionBar()
另外,請確保這是您的ActionBar
導入:
import android.support.v7.app.ActionBar
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.