改变清单后 - 主题错误

时间:2016-07-02 18:20:41

标签: java android xml manifest

我尝试在我的清单文件中更改我的启动器活动。更改后,我再次重新设置了我的代码(重新编辑,以便它与以前一样)。所以我只是在我的活动之间复制粘贴这段代码

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

重置我的代码后,该应用无法打开。 我收到了一个错误

java.lang.IllegalArgumentException:AppCompat不支持当前的主题功能,在我的setContentView(R.layout.activity_main)上停止;

我对这个问题感到非常沮丧,因为我没有在我的代码中更改任何内容(它在以前的工作中是不可思议的)

这是我的清单文件代码

<manifest package="com.inthessaloniki.cityguide"
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"

      android:installLocation="auto">

<!-- versionCode, versionName, minSdkVersion, targetSdkVersion properties are set via Gradle script -->

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- allows the API to access Google web-based services -->


<!-- maps API needs OpenGL ES 2.0 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="false"/>
<!--
You can easily change the main theme. Just modify application.android:theme attribute.
There are 8 main themes you can use:
    Theme.CityGuide.Blue
    Theme.CityGuide.Brown
    Theme.CityGuide.Carrot
    Theme.CityGuide.Gray
    Theme.CityGuide.Green
    Theme.CityGuide.Indigo
    Theme.CityGuide.Red
    Theme.CityGuide.Yellow
Don't forget to modify also MainActivity's theme.
-->

<application
    android:name=".CityGuideApplication"
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"

    android:label="@string/app_name"
    android:theme="@style/Theme.CityGuide.Indigo"
    tools:replace="android:icon">


    <!--
    Themes for MainActivity:
        Theme.CityGuide.TransparentStatusBar.Blue
        Theme.CityGuide.TransparentStatusBar.Brown
        Theme.CityGuide.TransparentStatusBar.Carrot
        Theme.CityGuide.TransparentStatusBar.Gray
        Theme.CityGuide.TransparentStatusBar.Green
        Theme.CityGuide.TransparentStatusBar.Indigo
        Theme.CityGuide.TransparentStatusBar.Red
        Theme.CityGuide.TransparentStatusBar.Yellow
    -->
    <activity
        android:name=".activity.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.CityGuide.TransparentStatusBar.Indigo"
        android:launchMode="standard">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".activity.PoiDetailActivity"
        android:label="@string/title_poi_detail"
        android:launchMode="standard"/>
    <activity
        android:name=".activity.TourDetailActivity"
        android:label="@string/title_tour_detail"
        android:launchMode="standard"/>
    <activity
        android:name=".activity.MapActivity"
        android:label="@string/title_map"
        android:launchMode="standard"/>
    <activity
        tools:replace="android:configChanges"
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize"/>
    <activity
        android:name=".activity.DescriptionDetailsActivity"
        android:label="@string/title_activity_description_details"
        android:theme="@style/Theme.CityGuide.TransparentStatusBar.Indigo">
    </activity>
    <activity
        android:name=".activity.MailFormActivity"
        android:label="@string/title_tour_detail"
        android:theme="@style/Theme.CityGuide.TransparentStatusBar.Indigo">
    </activity>

    <provider
        android:name=".content.PoiSearchRecentSuggestionsProvider"
        android:authorities="com.inthessaloniki.cityguide.content.PoiSearchRecentSuggestionsProvider"
        android:exported="false"/>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
    <meta-data
        android:name="com.google.android.gms.analytics.globalConfigResource"
        android:resource="@xml/analytics_global_tracker"/>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/maps_api_key"/>

</application>

主要活动代码

public class MainActivity extends AppCompatActivity implements DrawerAdapter.CategoryViewHolder.OnItemClickListener, OnSearchListener
{
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private ScrimInsetsFrameLayout mDrawerScrimInsetsFrameLayout;
    private DrawerAdapter mDrawerAdapter;

    private CharSequence mTitle;
    private CharSequence mDrawerTitle;
    private List<CategoryModel> mCategoryList;


    public static Intent newIntent(Context context)
    {
        Intent intent = new Intent(context, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return intent;
    }


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setupActionBar();
        setupRecyclerView();
        setupDrawer(savedInstanceState);

        // init analytics tracker
        ((CityGuideApplication) getApplication()).getTracker();
    }


    @Override
    public void onStart()
    {
        super.onStart();

        // analytics
        GoogleAnalytics.getInstance(this).reportActivityStart(this);
    }


    @Override
    public void onResume()
    {
        super.onResume();
    }


    @Override
    public void onPause()
    {
        super.onPause();
    }


    @Override
    public void onStop()
    {
        super.onStop();

        // analytics
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }


    @Override
    public void onDestroy()
    {
        super.onDestroy();
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // open or close the drawer if home button is pressed
        if(mDrawerToggle.onOptionsItemSelected(item))
        {
            return true;
        }

        // action bar menu behaviour
        switch(item.getItemId())
        {
            default:
                return super.onOptionsItemSelected(item);
        }
    }


    @Override
    protected void onPostCreate(Bundle savedInstanceState)
    {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }


    @Override
    public void onConfigurationChanged(Configuration newConfiguration)
    {
        super.onConfigurationChanged(newConfiguration);
        mDrawerToggle.onConfigurationChanged(newConfiguration);
    }


    @Override
    public void setTitle(CharSequence title)
    {
        mTitle = title;
        getSupportActionBar().setTitle("");
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/nexa-bold.otf");
        final TextView toolbarName = (TextView) findViewById(R.id.toolbar_title);
        toolbarName.setText(mTitle);


    }


    @Override
    public void onItemClick(View view, int position, long id, int viewType)
    {
        // position
        int categoryPosition = mDrawerAdapter.getCategoryPosition(position);
        selectDrawerItem(categoryPosition);
    }


    @Override
    public void onSearch(String query)
    {
        Fragment fragment = PoiListFragment.newInstance(query);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment).commitAllowingStateLoss();

        mDrawerAdapter.setSelected(mDrawerAdapter.getRecyclerPositionByCategory(0));
        setTitle(getString(R.string.title_search) + ": " + query);
    }


    private void setupActionBar()
    {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        ActionBar bar = getSupportActionBar();
        bar.setDisplayUseLogoEnabled(false);
        bar.setDisplayShowTitleEnabled(true);
        bar.setDisplayShowHomeEnabled(true);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);
    }


    private void setupRecyclerView()
    {
        // reference
        RecyclerView recyclerView = getRecyclerView();

        // set layout manager
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        // load categories from database
        loadCategoryList();

        // set adapter
        if(recyclerView.getAdapter()==null)
        {
            // create adapter
            mDrawerAdapter = new DrawerAdapter(mCategoryList, this);
        }
        else
        {
            // refill adapter
            mDrawerAdapter.refill(mCategoryList, this);
        }
        recyclerView.setAdapter(mDrawerAdapter);

        // add decoration
        List<Integer> dividerPositions = new ArrayList<>();
        dividerPositions.add(3);
        RecyclerView.ItemDecoration itemDecoration = new DrawerDividerItemDecoration(
                this,
                null,
                dividerPositions,
                getResources().getDimensionPixelSize(R.dimen.global_spacing_xxs));
        recyclerView.addItemDecoration(itemDecoration);
    }


    private void setupDrawer(Bundle savedInstanceState)
    {
        mTitle = getTitle();
        mDrawerTitle = getTitle();
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/nexa-bold.otf");
        final TextView toolbarName = (TextView) findViewById(R.id.toolbar_title);
        toolbarName.setText(mTitle);
        toolbarName.setTypeface(typeface);
        // reference
        mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_layout);
        mDrawerScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.activity_main_drawer);

        // set drawer

        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        mDrawerLayout.setStatusBarBackgroundColor(ResourcesHelper.getValueOfAttribute(this, R.attr.colorPrimaryDark));
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close)
        {
            @Override
            public void onDrawerClosed(View view)
            {
                toolbarName.setText(mTitle);
                getSupportActionBar().setTitle("");
                supportInvalidateOptionsMenu();
            }

            @Override
            public void onDrawerOpened(View drawerView)
            {
                toolbarName.setText(mTitle);
                getSupportActionBar().setTitle("");
                supportInvalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        // show initial fragment
        if(savedInstanceState == null)
        {
            selectDrawerItem(0);
        }
    }


    private void selectDrawerItem(int position)
    {
        long mCategoryId = mCategoryList.get(position).getId();

        Fragment fragment = null;
        if(mCategoryId==PoiListFragment.CATEGORY_ID_ALL || mCategoryId==PoiListFragment.CATEGORY_ID_FAVORITES ){
            fragment = PoiListFragment.newInstance(mCategoryId);
        }else{
            fragment = SubCategoryListFragment.newInstance(mCategoryId);
        }

        FragmentManager fragmentManager = getSupportFragmentManager();

        String categoryName = mCategoryList.get(position).getName();
        fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment, categoryName).addToBackStack(categoryName).commitAllowingStateLoss();

        mDrawerAdapter.setSelected(mDrawerAdapter.getRecyclerPositionByCategory(position));
        setTitle(categoryName);
        mDrawerLayout.closeDrawer(mDrawerScrimInsetsFrameLayout);
    }

    public void showPOIFragment(long categoryId, String categoryName){
        PoiListFragment fragment = PoiListFragment.newInstance(categoryId);
        FragmentManager fragmentManager = getSupportFragmentManager();

        fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment, categoryName).addToBackStack(categoryName).commitAllowingStateLoss();

        if (!TextUtils.isEmpty(categoryName)){
            setTitle(categoryName);
        }
    }

    public void showSubCategoryFragment(long categoryId, String categoryName){
        SubCategoryListFragment fragment = SubCategoryListFragment.newInstance(categoryId);
        FragmentManager fragmentManager = getSupportFragmentManager();

        fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment, categoryName).addToBackStack(categoryName).commitAllowingStateLoss();

        if (!TextUtils.isEmpty(categoryName)){
            setTitle(categoryName);
        }
    }

    private void loadCategoryList()
    {
        try
        {
            mCategoryList = CategoryDAO.readAll(-1l, -1l);
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }

        CategoryModel Thessaloniki = new CategoryModel();
        Thessaloniki.setId(PoiListFragment.CATEGORY_ID_THESSALONIKI);
        Thessaloniki.setName("Thessaloniki");
        Thessaloniki.setImage("drawable://" + R.drawable.ic_category_all);

        CategoryModel all = new CategoryModel();
        all.setId(PoiListFragment.CATEGORY_ID_ALL);
        all.setName(getResources().getString(R.string.drawer_category_all));
        all.setImage("drawable://" + R.drawable.ic_category_all);

        CategoryModel favorites = new CategoryModel();
        favorites.setId(PoiListFragment.CATEGORY_ID_FAVORITES);
        favorites.setName(getResources().getString(R.string.drawer_category_favorites));
        favorites.setImage("drawable://" + R.drawable.ic_category_favorites);



        mCategoryList.add(0,Thessaloniki);
        mCategoryList.add(1, all);
        mCategoryList.add(2, favorites);

    }


    private RecyclerView getRecyclerView()
    {
        return (RecyclerView) findViewById(R.id.activity_main_drawer_recycler);
    }

    @Override
    public void onBackPressed() {
        int count = getSupportFragmentManager().getBackStackEntryCount();
        if (count == 1) {
            finish();
        }else{
            getSupportFragmentManager().popBackStack();
            String name = getSupportFragmentManager().getBackStackEntryAt(count-2).getName();
            setTitle(name);
        }
//      super.onBackPressed();
    }
}

1 个答案:

答案 0 :(得分:0)

当我第一次使用API​​ 23在android stdio中创建项目时,我遇到了类似的问题,因此要解决这些问题,请尝试进行一些更改。 请在第一行更改您的活动代码: -

public class MainActivity extends AppCompatActivity

这些: -

public class MainActivity extends Activity

当我遇到同样的问题时,它对我有用。