I've updated my eclipse and ADT Plugin to the latest version recently and recognised some big changes. Whenever I create a new Android Application Project there appears a new appcompat_v7 library which wasn't present before and also a fragment_main.xml . Why is that? Why is the activity_main.xml file not preferred for activity layout directly anymore and why appcompat library is now included in every project ? I tried to remove eclipse/adt/sdk many times and remove the support library from sdk manager but got no result ! I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code here's a picture :http://i.stack.imgur.com/XJMfW.png
so how can I remove this dependency and thanks
Why is that?
Because Google engineers added that stuff to the new-activity templates, for at least the "BlankActivity".
Why is the activity_main.xml file not preferred for activity layout directly anymore
You are certainly welcome to use activity_main.xml
for whatever you want. It so happens that Google's current templates want you to use fragments. Google's templates are just templates. One can argue -- and I have, vehemently -- that a "BlankActivity" template should not be doing what it is doing. However, beyond that, it is just a template.
why appcompat library is now included in every project ?
Presumably, they wanted to start you off with a consistent action bar, even on older API levels.
I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code
I reported this issue a week or so ago.
so how can I remove this dependency
Step #1: Right-click over the project name in the Package Explorer, and choose Properties. Click on Android in the list of property categories on the left, and scroll down on the right to the bottom:
Step #2: In the list of attached library projects that you will now see in the properties dialog, you may see an entry akin to the "appcompat_v7_6" one that you see in the above screenshot. Your last digit will differ, and it may be that yours has a red X instead of a green checkmark. Regardless, if there is an entry for "appcompat_v7_NNN" in the list, click on it, then click the Remove button to the right of the list. Then, click the OK button to close up the dialog.
Step #3: In res/values/styles.xml
, change the parent of AppBaseTheme
from Theme.AppCompat.Light
to @android:style/Theme.Light
. In res/values-v11/styles.xml
, change the parent of AppBaseTheme
from Theme.AppCompat.Light
to @android:style/Theme.Holo.Light
. In rest/values-v14/styles.xml
change the parent of AppBaseTheme
from Theme.AppCompat.Light.DarkActionBar
to @android:style/Theme.Holo.Light.DarkActionBar
. Note that these values assume that you chose the default "Light theme with dark action bar" when you created the project -- you will need to make slight adjustments to those instructions for anything else.
Step #4: In res/menu/main/xml
, remove xmlns:app="http://schemas.android.com/apk/res-auto"
from the root <menu>
element and the app:showAsAction="never"
attribute from the <item>
element.
Step #5: In your activity (e.g., MainActivity
), change the parent class of the activity to something other than ActionBarActivity
-- FragmentActivity
would be a good choice, to minimize the number of other changes you will have to make immediately. Also, clean your imports (e.g., Ctrl-Shift-O).
At this point, other than perhaps cleaning your project (Project > Clean from the main menu), the appcompat
stuff should be ripped out of a project created using the "BlankActivity" template and with a "Navigation Type" of "None". Other templates, or navigation options on the "BlankActivity" template, will probably require more work.
Best ways to solve these:
Firstly in project,Right click->properties->Android
.There you can
see the red marked appcompat
placed in Reference
. Click that and
Remove it.
Delete fragment_main.xml and Appcompat file created in your Eclipse.
Edit and change your activity_main.xml like these:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
In res/values/styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
In res/values-v11/styles.xml you have to change like these:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
</resources>
In res/values-v14/styles.xml you have to change like these:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
Change your menu/main.xml like these:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
Finally change your MainActivity.java like these:
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
LikeWise you have to do it for creating a new project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With