How to get cloud based styling working in Android - android-studio

I have followed the instructions here https://developers.google.com/maps/documentation/get-map-id to associate my SupportMapFragment with the cloud based styling. However, nothing happens when I run the app. It's the same default map style. What am I missing?
So, I have the SupportMapFragment set up like this:
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
map:mapId="#string/mapId"/>
And the map ID is in strings.xml.

Related

How to add XML Google Pay Button in Flutter

My Flutter app uses Google Pay as a payment method. Following these guidelines, they provide XML buttons (which I have never dealt with).
How can I add one of these button to a flutter widget using dart?
There are different implementations for laying out content for Android versus Flutter.
The layout/googlepay_button.xml layout effectively describes the way the button appears, and drawable/googlepay_button_content.xml contains VectorDrawable file for the Google Pay button. flutter_svg should help you render the contents of the image.
To get this to work with Flutter, you would need to reproduce the xml layout as a Flutter widget tree.
Sample layout black/res/layout/googlepay_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="48sp"
android:background="#drawable/googlepay_button_no_shadow_background"
android:paddingTop="2sp"
android:contentDescription="#string/googlepay_button_content_description">
<LinearLayout
android:duplicateParentState="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:duplicateParentState="true"
android:src="#drawable/googlepay_button_content"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:duplicateParentState="true"
android:src="#drawable/googlepay_button_overlay"/>
</RelativeLayout>
It looks like SVG. Try to open all these XML files like SVG, and add it to assets folder in your project.

how to adjust flipper size in your android studio project?

I wanted to create slideshow in my main activity page. After implementing the flipper inside my app, I notice that the FlipperLayout got overlapped with my widget Toolbar. Inside my widget toolbar contains name of the user, where I call the user full name when they are logged into the app.
I'm not quite sure on how to adjust the flipper size to make sure that the slideshow will not overlap with my toolbar. And I want the flipper to be put below the toolbar. Can anyone help me ?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_layout"
android:layout_above="#id/btm_nav"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/purpleBoo"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark" >
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:layout_gravity="center"
android:textColor="#color/white">
</TextView>
</androidx.appcompat.widget.Toolbar>
<technolifestyle.com.imageslider.FlipperLayout
android:id="#+id/flipper"
android:layout_width="match_parent"
android:layout_height="219dp">
</technolifestyle.com.imageslider.FlipperLayout>
You can edit your FlipperLayout to add android:layout_marginTop="?attr/actionBarSize" attribute
<technolifestyle.com.imageslider.FlipperLayout
android:id="#+id/flipper"
android:layout_width="match_parent"
android:layout_height="219dp"
android:layout_marginTop="?attr/actionBarSize">
OR
You can use a LinearLayout at the root of your layout instead of a FrameLayout, with android:orientation="vertical". This is because the FrameLayout is intended for purposes where child view overlapping is desired.

Drag and Drop feature is not working in Android Studio. Can't even click to show attributes

I want to drag and drop elements into the Design View but I just can't. I can't even see the attributes aside when click into the screen or the default TextView that says 'Hello World!'. I tried restarting Android Studio, rebuild the project, and I still have the problem.
The code below is from my file 'activity_main.xml'.
How did happened?
I just tried to add a 'GridLayout' into the screen design, but to use it I had to install a library to use that grid layout and since I did that, I can't use the design view anymore.
Even I get an 'IDE Fatal Error' (screenshot below).
error ide image:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Remove
implementation 'com.android.support.constraint:constraint-layout:+'
from your build.gradle (app)
Hopefully Solve this problem

In Android Studio the widgets are moving up on the screen during emulation

I am new to both Stack Overflow and Android Studio and learning to code now.
I did a basic user and password layout in Android Studio like this:
When I ran this on emulator, it displays the widgets like this:
I tried to change the width of the EditText fields, buttons, but nothing I have tried seems to be working.
How do I solve this?
What am I missing or am I doing something wrong ?
Layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="233dp"
android:scaleType="fitStart"
android:visibility="visible"
app:srcCompat="#drawable/worldcurrency" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter ammount"
android:textSize="18sp" />
<EditText
android:id="#+id/dollar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="convert"
android:text="Convert" />
<TextView
android:id="#+id/rupees"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Your layout's parent is a ConstraintLayout, but it's lacking every constraint. ConstraintLayout is characterised by the ability to set constraints to every view, forcing its behaviour across screens of different sizes and orientations.
If you really want to use a ConstraintLayout I suggest taking a look at the ConstraintLayout Documentation. Once you've properly set the constraints, you should have an xml like this (note the constraint* attributes in my Views.
So, your layout has no constraints, it's likely it will end at "random" positions. Moreover, you've set the views coordinates with tools, which is valid only for the layout preview, not for runtime. And moreover, the use of absolute coordinates is very not recommended, since it can cause problems across different screen sizes.
If ConstraintLayout is an optional choice for you, you can change the layout parent to a LinearLayout with vertical orientation, I think it's more suitable for the layout you're building (I'm assuming this by your screenshots).Hope I helped, let me know. Good luck and happy coding!

Rotated Button (anim) disappears after Banner Ad appears

I have a button in the center of my screen, a spinner and a banner ad at the bottom. The app works perfectly on any phone that I've tried and also works fine in a galaxy 10.1 tablet. The button acts like a compass so I rotate it as the device moves. I load it on to an ASUS MeMo Pad 7" 800 x 1280 and it works great until the adMob banner shows up. At that point, the button appears to get overlayed and go invisible. Occasionally when the compas makes an adjustment to its rotation, the button flickers back - on/off.
This app works on 5.1, 4.4.2 and passes the app store prelaunch tests. I've used the virtual device in Studio using Nexus 7 (800 x 1280) with 4.4.4 and it works. I can't determine if there is something different in the ASUS tablet or a bug in 4.4.4.
My layout looks like this:
<?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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/point"
tools:context=".MainPlay">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:id="#+id/baseView">
</ImageView>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/adUnitId"
tools:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_above="#+id/adView"
android:layout_alignParentTop="true"
android:id="#+id/bView"
android:background="#color/clear"
android:weightSum="1">
<TextView
android:id="#+id/filler"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.56">
</TextView>
<Button
android:id="#+id/target"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#drawable/pointer"
android:gravity="center"
android:text="#string/shake"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<TextView
android:id="#+id/filler1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.35">
</TextView>
<Spinner
android:id="#+id/spinner"
android:layout_width="250dp"
android:layout_height="60dp"
android:background="#color/dark_background"
android:popupBackground="#color/light_background"
android:layout_gravity="center_horizontal|center"/>
<TextView
android:id="#+id/spinnerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="italic"
tools:textColor="#color/myWhite"
android:layout_weight="0.14"
/>
</LinearLayout>
</RelativeLayout>
I've tried to reorder the layout but all that acts as expected. Putting the adview first makes it disappear under the imageview (expected). The code waits for a little while before displaying the ad (loadAd). If I don't load the ad, the button stays fine. If the ad takes a half-second to load next one, the button appears briefly.
Has anyone seen this behavior anywhere? Any suggestions on how to approach? This may only be an issue on this device but how is that possible and how would I know?
Thank you.
Edit: I found another app on the Play Store that exhibits this same behavior when spinning a button only on the ASUS MeMo Pad 7 LTE. I've found a few spinning button apps that appear to work fine.
I've tried many different layout files but no matter what level I put the Ad on it still makes the button disappear after I rotate it. I've tried animation utils (RotateAnimation) as well as 9 old android libraries. No difference.
PROGRESS (but no fix)-: It seems that if I do not animate the button, it stays visible. I'm assuming that something in the animation code is interacting with the button's Z level when the Ad shows up. As soon as I start the animation (either by clicking or rotating the device) the button disappears. (sigh)
After much searching on related issues, I found how to stop the flickering/disappearing button when Admob shows up using:
adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
See this answer from 2014.
Hope this helps.

Resources