gpt4 book ai didi

android - 后退导航按钮没有功能

转载 作者:行者123 更新时间:2023-11-30 01:21:57 25 4
gpt4 key购买 nike

我已经浏览了许多堆栈溢出问答,但我无法为我的后退导航按钮提供功能。可能是什么错误

如果有人能帮助我,因为我明天必须提交我的项目

我的java代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime);
TextView disp1 =(TextView) findViewById(R.id.textView2);
disp1.setText("Displaying 1 of 24");
TextView displa = (TextView) findViewById(R.id.textView);
displa.setText(" China is the source of 70% of the worlds pirated goods.,");
getActionBar().setDisplayHomeAsUpEnabled(true);


}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_crime, menu);


return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

case R.id.what:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,"Hey,I saw an amazing fact from Fact-O-Mania" +"\n"+"\n"+fact[i]);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
int id = item.getItemId();
break;

case R.id.home :

finish();
}
return true;
}

最佳答案

您应该在 list xml 中定义您的父 Activity ,以告知在按下工具栏的后退按钮时导航到哪里。

 <activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- The meta-data element is needed for versions lower than 4.1 -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>

关于android - 后退导航按钮没有功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36958835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com