Android应用安装但未显示

时间:2014-06-15 01:15:45

标签: android

我一直在四处寻找,似乎无法找到答案。我的Android应用程序编译正确,没有错误或任何东西,它安装正确,但它不会出现在应用程序抽屉中,并且"打开"按钮显示为灰色。这是我的主要活动

package com.dogger20011.app;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

 public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new                         

PlaceholderFragment()).commit();
    }
  }

@Override
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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.Downloads) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}
 }

有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:2)

您将主要活动放置在意图过滤器之后,该过滤器将mainActivity作为启动器。请更正下面的XML(基本上,MainActivitiy相关内容)并删除maxSDKVersion

中的Uses-permission标记

最后它应该是这样的:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dogger20011.app"
android:versionCode="1"
android:versionName="1.0.5" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">

<activity
    android:name="com.dogger20011.app.MainActivity"
    android:label="@string/app_name"/>

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<activity
        android:label="@string/app_name"
        android:name=".AppActivity"/>
<activity
        android:label="@string/app_name"
        android:name=".AppActivity_modD"/>
<activity
        android:label="@string/app_name"
        android:name=".App2Activity"/>
<activity
        android:label="@string/app_name"
        android:name=".AppActivity_ModD2"/>

</application>
</manifest>

答案 1 :(得分:0)

你的MainActivity不应该有所作为,这完全取决于清单。您的主要活动块应如下所示:

<activity
    android:name="com.dogger20011.app.MainActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

请注意,<intent-filter>块需要嵌套在<{strong> <activity>块中。