After trying just about everything, I cannot get the color preview to show in the XML editor in Android Studio. In my colors.xml file, I expect a line like <color name="colorAccent">#1AD270</color> to show a small square to the left of it in the gutter previewing the color.
Weirdly, it only happens in this particular project. When I open other Android Studio projects, the gutter icons appear normally.
I have completely reset my Android Studio settings, disabled/enabled gutter icons and changed the gutter background, none of which worked. Any help?
Turns out that the color previews do not show up if you don't have an activity in your project. After adding the first activity, the color preview icons suddenly appear. Weird!
Just to expand on zwh's comment, you bizarrely need to have a layout xml in the layout folder of the module.
It doesn't need to be linked to an activity at all, or mentioned anywhere, just has to exist! I created one called dummy_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- If this file is deleted, colors.xml doesn't show colour gutter icons https://stackoverflow.com/a/65395717/608312 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Related
I am developing an app with Android Studio 2.2.3 and I'm facing a problem I did not find before: if I add an Activity from a template such as Basic Activity, the newly created activity will let the device status bar display
If I add instead an activity from the Empty Activity template, no status bar shows up any more.
Reading through the layout files, I see that the Basic activity uses a android.support.design.widget.CoordinatorLayout whereas the Empty Activity uses a RelativeLayout. I cannot find any other differences, neither in the manifest. I programmed some apps with Eclipse some time ago and the status bar was there, even with the RelativeLayout, as far as I remember.
Any suggestion?
Thanks in advance, regards
Edit:
Status bar does not relate with layout. It is about the theme defined in the styles.xml. Can you check which theme is applied your activity?
Thanks steve for your suggestion: the behavior is due to
Yet another question: keeping this no-actionbar theme, why is my textbox not aligned with the top of the screen, like this:
My activity layout is:
<?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:id="#+id/activity_main4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.pgsoftware.firebasepublisher.Main4Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test string"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"/>
</RelativeLayout>
and with the Layout inspector I get the following UI structure:
The LinearLayout at the top has a 72dp top-padding which I can't find digging into the themes: any suggestion?
Thanks in advance, regards
Please check the android:appTheme="#style/AppTheme" option in the manifest file . Check the theme option in res>style.xml file . Copy the stylesheet and paste in comment to see.
I made a navigation icon through the Vector Asset wizard in Android Studio to place in my Toolbar. By default, the color of the image is black. It doesn't give me the option to change it in the wizard. So is there a way to change the color in xml? This is how it is set in my toolbar layout file:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="#drawable/nav_menu_icon">
</android.support.v7.widget.Toolbar>
As you can see, the image is set as app:navigationIcon="#drawable/nav_menu_icon". So is it possible to change the icon's color? I tried this solution but it wasn't working for me. The other solutions were given in code but I would like to use an xml version if possible. Also, my app is supporting API 16 and later.
You can change color of "nav_menu_icon".
Need to open nav_menu_icon.xml in studio or any editors and change the attribute "fillColor".
It's android:fillColor="#FF000000" by default.
I have a list preference in my preference category, everything looks good except that there is no arrow-down icon beside it.
I changed my theme from light to dark, but no change regarding this arrow icon. I think this is a feature of list preference, but don't know why just not shown!
Any help is great appreciated!
I want to upload images about it, but with no reputation, it is not allowed! what a shame!
I found a list preference example on internet
http://viralpatel.net/blogs/android-preferences-activity-example/
this example also doesn't have arrow-down icon, exactly the problem I have.
Unfortunately, they removed the Arrow in HoneyComb (API Level 11).
And never put it back!!
Anyway, there's a trick you can apply to overcome this limitation:
In your ListPreference attributes, add a line like this:
android:widgetLayout="#layout/arr_dn"
having previously defined a file called arr_dn.xml in your res/layout path, containing the following lines:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="4dp"
android:src="#drawable/arr_dn"
/>
Of course, you need to put your graphics (I called it arr_dn.png) in your res/drawable path.
I tested under several API levels, including 2.2 and 4.0.3 and it's working well.
I have just created a new android project in eclipse and added a relative layout.
I can add controls using XML but I can't add any controls using the graphic editor.
My current code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
When I click on a widget - say a button, a black circle with a diagonal bar in it shows briefly then disappears, and I cannot drag the control onto the editor.
If I create the control in code, it shows up ok, but I can't select it with a left click, only right click. Then once selected it cannot be moved, and moving the handles does not resize the control. It can only be be deleted.
Any clues as to why this might be?
I'm using version 4.2.2
I don't knoiw what else to include that might be of assistance.
Ok I have created a background image in Inkscape. Exported that image and it looks correct, when I open it from Eclipse. However, when I build the project and apply that background to the Layout, it shows the complete opposite in the designer and on the device.
Here is what the image is supposed to look like. Correct background
Here is what the image looks like in the Eclipse Designer.Incorrect background.
Here is my Xml on a brand new Xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_view_bg"
android:orientation="vertical" >
</LinearLayout>
I am utterly confused on this one. Any help is greatly appreciated.
You are most likely using a theme where the background in dark. As your background gradient is transparent the black background is showing through.
Switch to a light theme.