2

I am trying to display google map inside dialog window. For this dialog i am using following lines of code:

final Dialog dialog = new Dialog(SetProfileOnlineActivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.pick_location_layout);
        Window w = dialog.getWindow();
        w.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        dialog.show();

pick_location_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">


    <com.google.android.gms.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/myLl"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

    <LinearLayout
        android:id="@+id/ll_map_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@color/white"
        android:orientation="horizontal"
        >
        <EditText
            android:id="@+id/et_search_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="Search"
            android:padding="8dp"
            android:layout_weight="1"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:maxLines="1"
            android:background="@android:color/transparent"
             />
        <ImageButton
            android:id="@+id/ib_search_map"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@drawable/search"
            />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/myLl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent">

        <Button
            android:id="@+id/btn_map_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/red"
            android:text="Cancel"
            android:textColor="@color/white"
            android:textSize="@dimen/_18sdp" />

        <Button
            android:id="@+id/btn_map_ok"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/green"
            android:text="Ok"
            android:textColor="@color/white"
            android:textSize="@dimen/_18sdp" />
    </LinearLayout>

    <Button
        android:id="@+id/btn_switch_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:text="Switch View"
        app:layout_constraintBottom_toTopOf="@+id/myLl"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


</android.support.constraint.ConstraintLayout>

Now my problem is that my map is showing darker. I am also displaying edittext in dialog which is showing perfectly but map is only component which is showing darker as shown in image. So, is there any way to make mapview brighter as other components?

enter image description here

ADM
  • 20,406
  • 11
  • 52
  • 83
Jaydip Kalkani
  • 2,493
  • 6
  • 24
  • 56

1 Answers1

3

Update for MapView

Solution for mapView in dialog is removing background dim like this (adjusted for your code, just paste before dialog.show()):

        w.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Bad part is I've found this solution in 5 year old question

Previous answer

I've just checked with "newer map" solution (read more here):

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    app:mapType="normal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and it shows bright --image was here--

Variag
  • 1,056
  • 10
  • 25
  • I can't use fragment because i had done lots of operations with map and now i am just fixing the view. If i use fragment then it will mess up all the operations. Is there any other way to do it? – Jaydip Kalkani Mar 13 '18 at 03:55
  • Have you tried adding background to root element in xml? `` – Variag Mar 13 '18 at 08:43
  • no, i doesn't tried. Let me try it out but which background i should have to add? transperant or any other? – Jaydip Kalkani Mar 13 '18 at 08:45
  • Transparent is by default, try white `android:background="#FFFFFF"` – Variag Mar 13 '18 at 08:47
  • okay..let me try and get back to you soon.Thanks – Jaydip Kalkani Mar 13 '18 at 08:48
  • Not working man. – Jaydip Kalkani Mar 13 '18 at 09:11
  • That's strange. I'm testing in Android 7.0 and it shows as it should. What is your device and Android version? Also is there any code that modifies your `mapView` or its style? – Variag Mar 13 '18 at 09:38
  • I have tested this app on Redmi 3s having marshmallow , Micromax canvas spark having lolipop and android emulator having naugat. All shows me same result and yes i am using code which modifies map style. When user clicks "switch view" button, map style will changed from normal to satelite view and vice versa. There is no any code which changes mapview style. – Jaydip Kalkani Mar 13 '18 at 09:46
  • are you using same code which i have posted in my question for testing or you have done any modification in it? – Jaydip Kalkani Mar 13 '18 at 09:47
  • Check my updated answer, it should solve your problem now. – Variag Mar 13 '18 at 09:49
  • Very very very big thanks to you. Updated answer has solved my problem. Thank you. – Jaydip Kalkani Mar 13 '18 at 09:52