我正在创建一个应用,其中我在一个项目中创建了导航抽屉,并在启动画面和一个随机活动 >第二个项目。 所以我试图合并他们。我设置了启动画面和随机活动,因此合并已正确完成。
然后我在随机活动上设置按钮,重定向到主要活动(此处为homeActivity)但是当我点击按钮时,它会获得白屏。
在homeAcitivity中我有使用导航抽屉作为我已经提到所以如何解决mainActivity上的白屏问题??? 我在这里看到了一些问题,但我没有得到我的解决方案......
使用android studion 2.1.2 gradle版本2.10
由于
CODE
这里是mainActivity(这里是homeActivity)
public class homeActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ListView list;
String[] menutitles;
String[] menudescriptions;
int images[]={R.drawable.mouse, R.drawable.keyboard, R.drawable.filemanager, R.drawable.media, R.drawable.power};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Resources res = getResources();
menutitles=res.getStringArray(R.array.titles);
menudescriptions=res.getStringArray(R.array.descriptions);
list = (ListView) findViewById(R.id.listView);
listadapter adptr=new listadapter(this,menutitles,images,menudescriptions);
list.setAdapter(adptr);
onclick();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
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;
}
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_mouse) {
Intent intentu = new Intent("com.example.admin.pcremote.MouseActivity");
startActivity(intentu);
} else if (id == R.id.nav_keyboard) {
Intent intentu = new Intent("com.example.admin.pcremote.KeyboardActivity");
startActivity(intentu);
} else if (id == R.id.nav_filemanager) {
Intent intentu = new Intent("com.example.admin.pcremote.FilemanagerActivity");
startActivity(intentu);
} else if (id == R.id.nav_media) {
Intent intentu = new Intent("com.example.admin.pcremote.MediaActivity");
startActivity(intentu);
} else if (id == R.id.nav_power) {
Intent intentu = new Intent("com.example.admin.pcremote.PowerActivity");
startActivity(intentu);
}else if (id == R.id.nav_send) {
AlertDialog.Builder builder = new AlertDialog.Builder(homeActivity.this);
builder.setMessage("Do You Want To Exit?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.setTitle("Exit!!");
alert.show();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
activity_main.xml中(homeActivity)
<?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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" >
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true"
tools:context="com.example.admin.pcremote.homeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.admin.pcremote.homeActivity"
tools:showIn="@layout/app_bar_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</ListView>
</RelativeLayout>
这是其他活动 在这个我试图导航其工作的其他活动,但不知道与mainActivity
AlertDialog.Builder builder = new AlertDialog.Builder(ipInfo.this);
builder.setTitle("Warning");
builder.setMessage("IP address or port number cannot be empty!!!").setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}}).setNegativeButton("Continue Anyway", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent inst = new Intent(ipInfo.this,homeActivity.class);//here is redirection of home activity
startActivity(inst);
}});
AlertDialog alert = builder.create();
alert.setIcon(R.drawable.ic_error_outline_black_24dp);
alert.show();
启动画面
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome_splash);
getSupportActionBar().hide();
Thread ssThread = new Thread(){
@Override
public void run() {
try {
StartAnimations();
sleep(3500);
Boolean isfirstrun = getSharedPreferences("PREFERENCES",MODE_PRIVATE).getBoolean("first",true);
if(isfirstrun){
Intent inst = new Intent(welcome_splash.this,install_server.class);
startActivity(inst);
getSharedPreferences("PREFERENCES",MODE_PRIVATE).edit().putBoolean("first",false).commit();
}else{
Intent starthomeScreen = new Intent(getApplicationContext(),ipInfo.class);
startActivity(starthomeScreen);}
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
ssThread.start();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
RelativeLayout l = (RelativeLayout) findViewById(R.id.rel_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.logo);
iv.clearAnimation();
iv.startAnimation(anim);
}
logcat是
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 574: Landroid/content/ContextWrapper;.getObbDirs ()[Ljava/io/File;
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x1356
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.app.Activity.startPostponedEnterTransition, referenced from method com.example.admin.pcremote.homeActivity.access$super
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 249: Landroid/app/Activity;.startPostponedEnterTransition ()V
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x135c
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.content.ContextWrapper.getExternalCacheDirs, referenced from method com.example.admin.pcremote.homeActivity.access$super
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 565: Landroid/content/ContextWrapper;.getExternalCacheDirs ()[Ljava/io/File;
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x13ce
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.app.Activity.onEnterAnimationComplete, referenced from method com.example.admin.pcremote.homeActivity.access$super
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 145: Landroid/app/Activity;.onEnterAnimationComplete ()V
01-01 16:55:22.725 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x1411
01-01 16:55:22.735 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 537K, 9% free 8425K/9159K, paused 2ms, total 2ms
01-01 16:55:22.735 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 9.256MB for 1048588-byte allocation
01-01 16:55:22.745 4495-4499/com.example.admin.pcremote D/dalvikvm: GC_CONCURRENT freed 4K, 8% free 9444K/10247K, paused 10ms+0ms, total 12ms
01-01 16:55:22.755 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed <1K, 8% free 9444K/10247K, paused 2ms, total 2ms
01-01 16:55:22.755 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 11.501MB for 2359308-byte allocation
01-01 16:55:22.765 4495-4499/com.example.admin.pcremote D/dalvikvm: GC_CONCURRENT freed 0K, 7% free 11748K/12615K, paused 1ms+1ms, total 5ms
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve direct method 19953: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve direct method 19953: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.widget.ArrayAdapter.getDropDownViewTheme, referenced from method com.example.admin.pcremote.listadapter.access$super
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 19710: Landroid/widget/ArrayAdapter;.getDropDownViewTheme ()Landroid/content/res/Resources$Theme;
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x014a
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.widget.ArrayAdapter.setDropDownViewTheme, referenced from method com.example.admin.pcremote.listadapter.access$super
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 19720: Landroid/widget/ArrayAdapter;.setDropDownViewTheme (Landroid/content/res/Resources$Theme;)V
01-01 16:55:22.775 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x01d4
01-01 16:55:22.805 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 3414K, 32% free 8697K/12615K, paused 2ms, total 4ms
01-01 16:55:22.805 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 9.084MB for 589836-byte allocation
01-01 16:55:22.815 4495-4499/com.example.admin.pcremote D/dalvikvm: GC_CONCURRENT freed 11K, 27% free 9262K/12615K, paused 11ms+0ms, total 14ms
01-01 16:55:22.815 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 258K, 29% free 9015K/12615K, paused 1ms, total 2ms
01-01 16:55:22.815 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 9.808MB for 1022412-byte allocation
01-01 16:55:22.825 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed <1K, 21% free 10013K/12615K, paused 2ms, total 2ms
01-01 16:55:22.825 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 0K, 21% free 10013K/12615K, paused 2ms, total 2ms
01-01 16:55:22.825 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 12.001MB for 2300412-byte allocation
01-01 16:55:22.835 4495-4499/com.example.admin.pcremote D/dalvikvm: GC_CONCURRENT freed 0K, 18% free 12260K/14919K, paused 1ms+0ms, total 4ms
01-01 16:55:22.845 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 1396K, 19% free 12175K/14919K, paused 2ms, total 2ms
01-01 16:55:22.845 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 12.918MB for 1048588-byte allocation
01-01 16:55:22.855 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed <1K, 18% free 13199K/16007K, paused 2ms, total 2ms
01-01 16:55:22.855 4495-4495/com.example.admin.pcremote D/dalvikvm: GC_FOR_ALLOC freed 0K, 18% free 13199K/16007K, paused 2ms, total 2ms
01-01 16:55:22.865 4495-4495/com.example.admin.pcremote I/dalvikvm-heap: Grow heap (frag case) to 15.168MB for 2359308-byte allocation
01-01 16:55:22.865 4495-4499/com.example.admin.pcremote D/dalvikvm: GC_CONCURRENT freed 0K, 16% free 15503K/18375K, paused 0ms+1ms, total 3ms
01-01 16:55:22.895 4495-4495/com.example.admin.pcremote I/dalvikvm: Could not find method android.support.v7.widget.LinearLayoutCompat.drawableHotspotChanged, referenced from method android.support.design.internal.ForegroundLinearLayout.drawableHotspotChanged
01-01 16:55:22.895 4495-4495/com.example.admin.pcremote W/dalvikvm: VFY: unable to resolve virtual method 16053: Landroid/support/v7/widget/LinearLayoutCompat;.drawableHotspotChanged (FF)V
01-01 16:55:22.895 4495-4495/com.example.admin.pcremote D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
答案 0 :(得分:0)
最后,在审查了与主要活动相关的所有其他布局文件后,我们得到了解决问题的方法
解决方案 设计视图中 content_main.xml 的更改从 AppTheme.NoActionBar 到 AppTheme 并以正常方式显示活动...