gpt4 book ai didi

java - 由于 Intent,Action Bar 没有显示?

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

更新:我通过将 MainActivityFragment extends FragmentActivity 更改为 MainActivityFragment extends AppCompatActivity 来修复它。

谢谢大家。


如果我不评论 Intent,Action Bar 就会显示。如果我在 onCreate MainActivity 中运行 Intent,则操作栏不会显示。如何显示具有 Intent 的操作栏。我在下面提供了 Intent (主要 Activity )和 Android list 代码。

截图链接:

Non-Intent

Intent

主要 Activity .java :

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main); // this is the start layout
Intent intent = new Intent(this, MainActivityFragment.class);
startActivity(intent);
}

安卓 list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.romi1.popularmoviesapp">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<dependency>
<groupId>
info.movito
</groupId>

<artifactId>
themoviedbapi
</artifactId>

<version>
1.3
</version>
</dependency>

<activity android:name=".MainActivityFragment"></activity>
<activity android:name=".MoviesDetailAdapter"></activity>
</application>

</manifest>

样式.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!--Theme.AppCompat.Light.DarkActionBar-->
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

主要 Activity fragment :

public class MainActivityFragment extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.fragment_main);

movies = new Movies[1000];

jsonParser(json);

moviesAdapter = new MoviesAdapter(this, movies);

setContentView(R.layout.fragment_main);
GridView gridView = (GridView) findViewById(R.id.listView);
gridView.setAdapter(moviesAdapter);

// This for setting what happen when one of the movie is selected
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

// Make another fragment class for this Adapter
// And figure out away to send the clicked parcelable variable
Movies topRatedMovieJson = moviesAdapter.getItem(i);
Log.v(LOG_TAG, "topRatedMovieJson : " + i);
Log.v(LOG_TAG, "topRatedMovieJson : " + topRatedMovieJson.title.toString());
Intent intent = new Intent(getBaseContext(), MoviesDetailAdapter.class);
intent.putExtra("parcelable", topRatedMovieJson);
startActivity(intent);
}
});
}
}

更新:我通过将 MainActivityFragment extends FragmentActivity 更改为 MainActivityFragment extends AppCompatActivity 来修复它。

谢谢大家。

最佳答案

有两种方法可以做到这一点1.将该 Activity 更改为 fragment 2. 将 Actionbar 添加到第二个 Activity 的布局和您的 Activity 中。

关于java - 由于 Intent,Action Bar 没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38511884/

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