Android studio appcombat actionbar setup - java

I've managed somehow to add the action bar when i extend ActionBarAtcitivy, but what if i want to call for example: ListActivity and still have the action bar?
I have a strange feeling that i missed something when i added the appcombat library, because in the preview design window actionbar is never displayed, though if i launch the app, the action bar is there(But only if i extended the ActionBarActivity).
How i installed the actionbar:
I downloaded the library and the repository.
I added the compile com.android.support:appcompat-v7:21.0.3 in build.gradle.
I have the android:minSdkVersion="8" android:targetSdkVersion="21" declared in my build.gradle script.
Ive done these parts, as told in the android studio documentation.
Another interesting thing, when i'm trying to import the android.support.v7.app.ActionBar it just disappears immediately. whatsthat about?

You need to stick with ActionBarActivity if you want to use this library. For your particular case, instead of having a ListActivity, you should:
have an activity extending ActionBarActivity;
load a ListFragment into it, possibly from the support libraries as well (android.support.v4.app.ListFragment).
Regarding your second question, the "design" view will not show your toolbar if you load that at runtime. It just reads your layout XML file without running any code, according to the theme you have set. It should not be intended as a real, reliable preview of what your activity will look like. For that you need an emulator running the OS, or a real phone.

Related

How to create a navigation that open from bottom of screen?

I want to create some thing like drawer menu that open from bottom of screen.
some thing like blow image. Also I want to know is that any special name?
You can use BottomSheet library. It works on Android 2.1+
https://github.com/soarcn/BottomSheet
It's called a SlidingDrawer. It was on the SDK but got deprecated a while back.
That said, this thrid-party library should do the job just as good. I've used it in multiple projects.

Android Studio automatically changes button style. Why?

I just developed an app on Android Studio and I used normal default grey button of kitkat. But some time later I made a copy of that app (to make another project) and now in this copied app, new buttons as well as those old buttons are shown with some different style. I am confused as to where I got that new style. It looks cool but I don't want to lose it as automatically as I got it.
I am attaching an image, this will show the changes in design.
Either you are using Theme.Material or Theme.AppCompat, or something that inherits from those (e.g., Theme.AppCompat.Light), as the basis for your app's theme. Or, you have no theme, and you are running on an Android 5.0+ device, and so you get Theme.Material by default.
Both Theme.Material and Theme.AppCompat (the latter in conjunction with AppCompatActivity and the rest of the appcompat-v7 library) aim to implement the Material Design aesthetic, and Material Design says that button captions are in all caps.
add this line in style
<item name="android:textAllCaps">false</item>

Should I create a fragment for my app?

I'm a bit confused as to wether I should create a plain activity or a fragmentactivity. My app is displaying an expandableListView and a dialog. Thats it (pretty much).
I cannot find any instance that my app would be better if I used a fragmentActivtiy because first of all my app is not designed for tablets, and second I'm not adding or doing anything to my main activity during runtime to change the views.
My problem is that it seems it is a must to use fragments, because when I checked out Android dev site on dialogs, it only explains how to implement them using fragments. Are plain activities highly un-recommended or I just have to judge my app, and are all features such as dialogs available for plain activities? (And can someone please give me a link to a good source where I can learn about dialogs in a normal activity?)
http://developer.android.com/guide/topics/ui/dialogs.html
It says here that you should use a fragment but does that mean i have to go all out and make my main activity a fragment?
Here is some discussion about using Fragment or Activity for dialog: Show fragment as a dialog or as a usual activity
If you want to make your dialog as Activity, hope this tutorial helps:
How to create Dialog activity in Android?
A FragmentActivity is an Activity because it extends Activity See here. The question the mean to ask is really a question for your self, do you want your app to support API >= 11 (3.0 Honeycomb) or API >= 4?
In API 11 Android introduced the concept of Fragments to deal with creating apps particularly tablets. But to add support for all the devices still running < 11 they created the Support v4 library which is where FragmentActivity lives.
If you are not using Fragments at all then just use Activity because it's available at all API levels. (it just got added functionality in >=11). If you want to support >=4 and may use Fragments then use FragmentActivity and your covered. I noticed things in the v4 library have started to be deprecated (starting to be phased out by Google). Personally, I won't make a new app with API <14 and suggest you stay above 11.
As far as Dialogs go. You don't need to used a DialogFragment but same question above applies to API level. I typically just used Dialog to show mine even if I'm using Fragments.
Hopefully this clears some things up for you. Happy Codin'

What is fragment_main?

I've recently setup eclipse and the android SDK on a new computer but I fear something has gone wrong when setting it up.
When I create a new android project with a blank activity two files I've never seen before appear:
fragment_main.xml
and
appcompat_v7_2
What are they and do I need to worry about them?
appcompat-v7 :
As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs)
Reference : Why does Eclipse automatically add appcompat v7 library support whenever I create a new project?
Fragment_main :
fragment_main.xml is the Layout for the fragment.
Refer this : Building a Dynamic UI with Fragments
hope this helps
The first, let read code in MainActivity!
You can see fragment_main is layout of one fragment in it.
when application running, fragment will be added to layout and show this layout.
Let read more about here for understanding about fragment. It is very important if you want to make android app.

How to remove android v7 -app compat support

I am facing some problem in android suppport v7 app compat. is giving error that some jar missing. I want to make a simple hello world app with android support v4 or something, but how to remove android support v7?
It's a bit of a chore to remove it. It's easiest to just create a new project, unchecking "Create Activity" in the wizard and then add a new class to src.
But if you really, really want to remove the v7 stuff from an existing project, here's one way to remove it, the action bar, and the fragments stuff:
Delete the android.libary.reference line from project.properties, ignoring the warning at the top.
Change the type of MainActivity from ActionBarActivity to just Activity.
Delete the v7 and v4.Fragment imports.
Delete the whole "if (savedInstanceState)" statement from MainActivity.
Delete the PlaceholderFragment class from MainActivity.
Replace the contents of activty_main.xml file with the contents of fragment_main.mxl or your own layout.
If you didn't use your own layout, remove the tools:context attribute/value from activity_main.xml.
Edit each of the 3 styles.xml files (under values*) and change the parent of style AppBaseTheme to "android:Theme.Light" (or your choice).
Edit menu/main.mxl and remove the app:showAsAction attribute/value.
Organize imports and clean your project.
Just to be clear: this isn't something you really want to do for a real app, but more something that you might want to do if you're just creating a demo or proof of concept.
Edit:
Going forward, you can add an additional template that creates an Activity without appcompat_v7. You can get one by CommonsWare here. There's a nice write about it here.
For your information this happened because you upgraded your ADT to the most recent version (22 I think).

Categories