Java Splashscreen不显示,主活动不显示
我编写了一个测验应用程序,现在我正在为我的应用程序编写最后的步骤。我认为启动屏幕是个好主意。所以我在我的程序中添加了一个闪屏活动,并进行了设置,现在当我等待启动我的应用程序时,闪屏不会出现。错误在哪里 主要活动(QuizaActivity): } 启动XML:Java Splashscreen不显示,主活动不显示,java,android,splash-screen,Java,Android,Splash Screen,我编写了一个测验应用程序,现在我正在为我的应用程序编写最后的步骤。我认为启动屏幕是个好主意。所以我在我的程序中添加了一个闪屏活动,并进行了设置,现在当我等待启动我的应用程序时,闪屏不会出现。错误在哪里 主要活动(QuizaActivity): } 启动XML: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="amapps.impossiblequiz.Splash">
</android.support.constraint.ConstraintLayout>
Menu2 Java:
public class Menu2 extends AppCompatActivity {
private DrawerLayout mDrawerLayout2;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu2);
TextView txtScore = (TextView) findViewById(R.id.textScore2);
TextView txtHighScore = (TextView)findViewById(R.id.textHighScore);
ImageView imgTrophyView1 = (ImageView)findViewById(R.id.trophy1);
ImageView imgTrophyView2 = (ImageView) findViewById(R.id.trophy2);
Intent intent = getIntent();
int mScore = intent.getIntExtra ("score",0);
txtScore.setText("Your score is: " + mScore);
SharedPreferences sharedpreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE);
int applyView =sharedpreferences.getInt("currentscore",0);
SharedPreferences mypref =getPreferences(MODE_PRIVATE);
int highScore = mypref.getInt("highScore", 0);
if (highScore>= mScore)
txtHighScore.setText("High score: " + highScore);
else{
txtHighScore.setText("New highscore: " + mScore);
SharedPreferences.Editor editor = mypref.edit();
editor.putInt("highScore",mScore);
editor.commit();
}
if (applyView >=10 && applyView<20)
imgTrophyView1.setVisibility(View.VISIBLE);
if (applyView >= 20 && applyView<30){
imgTrophyView2.setVisibility(View.VISIBLE);}}
public void onClick(View view) {
Intent intent = new Intent(Menu2.this, QuizActivity.class);
startActivity(intent);
mToolbar = (Toolbar) findViewById(R.id.nav_action);
setSupportActionBar(mToolbar);
mDrawerLayout2 = (DrawerLayout) findViewById(R.id.drawerLayout2);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout2, R.string.open, R.string.close);
mDrawerLayout2.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView mNavigationView = (NavigationView) findViewById(nv2);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case (R.id.nav_home2):
Intent accountActivity2 = new Intent(getApplicationContext(), QuizActivity.class);
startActivity(accountActivity2);
}
return true;
}
});
}
@Override //Makes that the "Burger" Item, shows the Drawer if someone clicks on the simbol
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
public类Menu2扩展了AppCompative活动{
私人抽屉布局mDrawerLayout2;
私人行动bardrawertoggle mtogle;
私有工具栏mToolbar;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu2);
TextView txtScore=(TextView)findViewById(R.id.textScore2);
TextView txtHighScore=(TextView)findViewById(R.id.textHighScore);
ImageView imgTrophyView1=(ImageView)findViewById(R.id.trophy1);
ImageView imgTrophyView2=(ImageView)findViewById(R.id.trophy2);
Intent=getIntent();
int mScore=intent.getIntExtra(“分数”,0);
setText(“您的分数是:“+mScore”);
SharedReferences SharedReferences=GetSharedReferences(“mypref”,Context.MODE\u PRIVATE);
int applyView=SharedReferences.getInt(“currentscore”,0);
SharedReferences mypref=getPreferences(模式\私有);
int highScore=mypref.getInt(“highScore”,0);
如果(高分>=mScore)
setText(“高分:+highScore”);
否则{
setText(“新高分:+mScore”);
SharedReferences.Editor=mypref.edit();
编辑:putInt(“高分”,mScore);
commit();
}
如果(applyView>=10&&applyView=20&&applyView
在Manifest.xml中执行此操作
在Manifest.xml中执行此操作将
意图过滤器
从主活动移动到Manifest.xml
文件中的启动活动
<activity android:name=".QuizActivity"></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
在
manifest.xml
文件中将意图过滤器从主活动移动到启动活动
<activity android:name=".QuizActivity"></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
请显示您的清单。xmlI现在将添加清单。请务必仔细阅读标签说明[android studio]标记用于有关工具本身的问题,而不是一般编程问题。请显示您的清单。xmlI将立即添加它。可能的副本请务必仔细阅读标记说明-在[android studio]标记用于有关工具本身的问题,而不是一般编程问题。为什么OP应该设置屏幕方向?是否可以保留MainActivity的意图过滤器?这将避免应用程序中的自动旋转。自动旋转将重新启动活动。我只针对应用程序中的纵向模式。删除MainActivity.只为溅起水花而保留
谢谢工作正常,但现在“汉堡按钮”在菜单2上不见了。他注意到,当我现在构建应用程序2时,应用程序正在安装。一个与splah一起工作,另一个只与测验活动帮助一起工作?为什么OP应该设置屏幕方向?是否可以保留MainActivity的意向过滤器?这将避免应用程序中的自动旋转。自动旋转将重新启动活动。我只是在我的应用程序中以肖像模式为目标。删除用于MainActivity。仅保留用于Splash
谢谢工作正常,但现在菜单2上的“汉堡包按钮”不见了。他注意到,当我现在构建应用程序2时,应用程序正在安装。一个与splah一起工作,另一个仅用于测验活动帮助?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="amapps.impossiblequiz.Menu2"
android:id="@+id/drawerLayout2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/navigation_action"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@+id/textScore2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="71dp"
android:background="#f60"
android:paddingBottom="20dp"
android:paddingLeft="50dp"
android:paddingRight="100dp"
android:paddingTop="20dp"
android:text="Your score:"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/textHighScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textScore2"
android:layout_marginTop="20dp"
android:background="#1abc9c"
android:paddingBottom="20dp"
android:paddingLeft="50dp"
android:paddingRight="100dp"
android:paddingTop="20dp"
android:text="Highest score:"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColor="#ffffff"
android:textSize="20dp" />
<Button
android:id="@+id/tryAgain_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textHighScore"
android:layout_marginTop="26dp"
android:background="#000"
android:onClick="onClick"
android:text="Restart Quiz!"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/trophy1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tryAgain_button"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:layout_marginTop="37dp"
app:srcCompat="@mipmap/ic_person_black_24dp"
android:visibility="invisible"/>
<ImageView
android:id="@+id/trophy2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/trophy1"
android:layout_marginLeft="39dp"
android:layout_marginStart="39dp"
android:layout_toEndOf="@+id/trophy1"
android:layout_toRightOf="@+id/trophy1"
app:srcCompat="@mipmap/ic_launcher_round"
android:visibility="invisible"/>
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu2"
android:layout_gravity="start"
android:id="@+id/nv2"
app:headerLayout="@layout/navigation_header"
app:itemIconTint="@drawable/tint_color_selector2">
</android.support.design.widget.NavigationView>
<activity
android:name=".Splash"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".QuizActivity"></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>