eph*_*amd 5 android android-menu android-actionbar android-support-library android-actionbar-compat
我正在使用android-support-v7-appcompat.
在一个活动中,我想在操作栏中显示后退按钮.我做:
public class News extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_news_screen);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
和:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
System.out.println(item.getItemId()); // 16908332
System.out.println(R.id.home); // 2131034132
System.out.println(R.id.homeAsUp); // 2131034117
switch(item.getItemId())
{
case R.id.home:
onBackPressed();
break;
case R.id.homeAsUp:
onBackPressed();
break;
case 16908332:
onBackPressed(); // it's works
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
如果我通过id工作使用数值滤波器,但我认为ID是由R生成的,因此可以改变,因此使用R.id. .任何的想法?
flx*_*flx 14
操作栏中的主页/后退图标具有ID android.R.id.home
.你可以找那个id.
android.R.*中的值永远不会改变并静态链接.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.home:
onBackPressed();
break;
case R.id.homeAsUp:
onBackPressed();
break;
case android.R.id.home:
onBackPressed();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4523 次 |
最近记录: |