Why is my layout not showing in Android Studio? - android

As you can see, I have a text view and a button but none of it is showing on the device. The device is empty, so I'm wondering how can I get these things to show? Nothing so far has been working, I already tried clicking on the magic wand.

This is one of the problems, I Encountered while working in android.
You have to edit your res/values/styles.xml file
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Steps are as following:
Go to res/values/
open styles.xml
change from -> style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"
change to -> style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"
(Just prepend "Base." to "Theme".)
Save the file and check Preview now.
Preview will Work Perfeclty now.

Related

Android Studio improper content_main xml on fresh install?

I just got android studio and I have some questions as my screen is different from the tutorial on lynda.com . The design tab for my content_main.xml file is just a blue square
However, the tutorial has this screen instead.
. This seems to fix itself when I closed the project and reopened it. However, instead of Hello World the tutorial has in the middle of the screen, I have android...Coordinator Layout as seen below. What have I done wrong as I literally just downloaded Android Studio...
make sure your styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Make sure style is (parent="Base.Theme.AppCompat.Light.DarkActionBar">)

All views disappear when I select the apptheme .. android Studio?

put when I change the theme to (Holo Theme) it back again screen ..
apptheme:
holotheme:
Manifest:
Try to edit your res/values/style.xml e.g. :
<style name="AppTheme" parent="AppBaseTheme"/>
It is just an example. I think there's nothing behind your "AppTheme" right now.

Why does select theme in Android Studio cause my layout become different

i using android studio to start develop apps, but i have some question about "Select Theme" in android studio. First, i noticed i select "NoActionBar" option, the layout will be like
The statusbar has no color, but after when i change to "AppTheme", the layout became
I had double check the code in styles.xml, but there are no changes. I really can't figure out about this. Can anyone explain this to me? Thank in advance.
**I have figured out actually select theme only the preview, it doesn't change my XML layout.
you will find this in styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
In your layout, two things are happening here
1. Your layout have a toolbar in its xml. So toolbar always showing.
2. the above pic will give you an idea about how the material theme isapplying with colors.
Hope this helps you.
check the colorPrimary and the colorPrimaryDark in your color.xml file

Android designer complains when I tryo to use design support library components

I am trying to implement a TabLayout for my application, so I add the support libraries, head into the XML editor of Android Studio, and begin typing <android.support.design.widget.TabLayout>. I get the usual issues of having to set a height and width, but I also seem a NOTE below stating:
Failed to find '?attr/colorPrimaryDark' in current theme.
(3 similar errors not shown)
Ok, I have and android:colorPrimaryDark set in my styles.xml. I have no idea what this ?attr/colorPrimaryDark is so I attempt to add it to my styles (which inherit from Theme.Material.Light) like:
<item name="?attr/colorPrimaryDark">#abcdef</item>
This does not fix the issue. Why am I getting this message? How do I fix the issue with this support library?
You must define the color palette in your style once your theme inherits the material theme.
Here is the code suggested on the google documentation.
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
In this code, they are referencing to their colors.xml resource file, but you can hard code colors straight into the style file.
One this is done, make sure that you don't have conflicting styles in different values folders in your resources.

Android studio preview pane not rendering ActionBar?

I'm running the latest version of android studio ,Problem is the preview pane does not render the ActionBar when any of the AppCompat themes are used, if i change the theme of the preview pane it works fine(Not change actual theme) ,but is there any discepency in doing this,
my styles.xml is as follows
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
when the preview pane is set to AppTheme ,the ActionBar ain't shown ,however it works fine in my device and AVD,
As you can see this makes it hard to debug and test the ActionBar
Please suggest some fix to this and how exactly does a AppCompat theme differ from an ordinary one?,I'm just an android beginner .
Thanks!
It is a bug: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=78944
Unfortunately it is low priority.
Update: set the preview to API 22
In my styles.xml I had
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
had to change it to just
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
There is culprit in your MainActivity(which ever your activity) when your are using app.compact.v7 your are supposed to extend ActionBarActivity instead Activity

Categories

Resources