1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android Fragment transparency problem

Discussion in 'Android Development' started by PaulR75, Jul 8, 2017.

  1. PaulR75

    PaulR75 Lurker
    Thread Starter

    Hi,

    Is there a simple way or hack to solve the transparency issu in Fragments.

    I have tried many propositions on other forums but non actually work, like coloring the background ...

    see attached pic for visual of the issu.

    tks :)
     

    Attached Files:



  2. Deleted User

    Deleted User Guest

    What are you trying to do?
    It would help to see your code, and layout XML
     
  3. PaulR75

    PaulR75 Lurker
    Thread Starter

    Hello,

    Thank you for your reply.

    I am using the Drawers template where the menu slides from left side. Now whatever is on the main screen is still visible from the transparency (!) of the Fragment. Searching for this i see i am not the only one with this problem and none of the responses i came to find are working or seem to me like they are to far fetched to be implementable without triggering a domino effect in my code.

    I find it funny in the 1st place that the Fragment backgrounds should come transparent by default ! I see a bunch of apps using the drawers that dont have this problem so, i'm sure there's got to be a simple way to avoid this transparency, would it be a simple hack.

    in content_main.xml
    Code (Text):
    1.  
    2. <FrameLayout
    3.     android:id="@+id/content_frame"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="match_parent"
    6.     tools:layout_editor_absoluteY="8dp"
    7.     tools:layout_editor_absoluteX="8dp">
    8. </FrameLayout>
    9.  
    in MainActivity.java
    Code (Text):
    1.  
    2.    @Override
    3.     public boolean onOptionsItemSelected(MenuItem item) {
    4.         // Handle action bar item clicks here. The action bar will
    5.         // automatically handle clicks on the Home/Up button, so long
    6.         // as you specify a parent activity in AndroidManifest.xml.
    7.         int id = item.getItemId();
    8.  
    9.         //noinspection SimplifiableIfStatement
    10.         if (id == R.id.action_settings) {
    11.             return true;
    12.         }
    13.  
    14.         return super.onOptionsItemSelected(item);
    15.     }
    16.  
    17.     @SuppressWarnings("StatementWithEmptyBody")
    18.     @Override
    19.     public boolean onNavigationItemSelected(MenuItem item) {
    20.         // Handle navigation view item clicks here.
    21.         int id = item.getItemId();
    22.         android.app.FragmentManager fragmentManager = getFragmentManager();
    23.  
    24.         if (id == R.id.nav_first_layout) {
    25.             fragmentManager.beginTransaction()
    26.                     .replace(R.id.content_frame
    27.                             , new FirstFragment())
    28.                     .commit();
    29.  
    30.         } else if (id == R.id.nav_second_layout) {
    31.             fragmentManager.beginTransaction()
    32.                     .replace(R.id.content_frame
    33.                             , new SecondFragment())
    34.                     .commit();
    35.  
    36.         } else if (id == R.id.nav_third_layout) {
    37.             fragmentManager.beginTransaction()
    38.                     .replace(R.id.content_frame
    39.                             , new ThirdFragment())
    40.                     .commit();
    41.  
    42.         } else if (id == R.id.nav_fourth_layout) {
    43.             fragmentManager.beginTransaction()
    44.                     .replace(R.id.content_frame
    45.                             , new FourthFragment())
    46.                     .commit();
    47.  
    48.         } else if (id == R.id.nav_fifth_layout) {
    49.             fragmentManager.beginTransaction()
    50.                     .replace(R.id.content_frame
    51.                             , new FifthFragment())
    52.                     .commit();
    53.  
    54.         } else if (id == R.id.nav_sixth_layout) {
    55.             fragmentManager.beginTransaction()
    56.                     .replace(R.id.content_frame
    57.                             , new SixthFragment())
    58.                     .commit();
    59.  
    60.         } else if (id == R.id.nav_seventh_layout) {
    61.             fragmentManager.beginTransaction()
    62.                     .replace(R.id.content_frame
    63.                             , new SeventhFragment())
    64.                     .commit();
    65.  
    66.         } else if (id == R.id.nav_share) {
    67.  
    68.         } else if (id == R.id.nav_send) {
    69.  
    70.         }
    71.  
    72.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    73.         drawer.setScrimColor(Color.BLACK);
    74.         drawer.closeDrawer(GravityCompat.START);
    75.         return true;
    76.     }
    77. }
    78.  
    and the layouts that are triggered open
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="match_parent"
    6.  
    7.     android:clickable="true"
    8.     android:focusable="true"
    9.     android:background="@android:color/black">
    10.  
    11.  
    12.     <TextView
    13.         android:id="@+id/textView2"
    14.         android:layout_width="wrap_content"
    15.         android:layout_height="wrap_content"
    16.         android:layout_alignParentTop="true"
    17.         android:text="@string/first_layout_page"
    18.         android:textAlignment="center"
    19.         android:textSize="20sp"
    20.         android:layout_alignParentRight="true"
    21.         android:layout_alignParentEnd="true"
    22.         android:layout_alignParentLeft="true"
    23.         android:layout_alignParentStart="true" />
    24.  
    25.     <WebView
    26.         android:layout_width="match_parent"
    27.         android:layout_height="match_parent"
    28.         android:layout_centerHorizontal="true"
    29.         android:layout_below="@+id/textView2"
    30.         android:background="@android:color/black"
    31.  
    32.         />
    33.  
    34. </RelativeLayout>
    35.  
    the background "color" black have absolutely no effect on results. At this point keeping them in the code just to remember i tried them out.
     
Loading...
Similar Threads - Android Fragment transparency
  1. androidnewbie12
    Replies:
    2
    Views:
    69
  2. hawkeyefxr
    Replies:
    0
    Views:
    62
  3. BrickHouse
    Replies:
    4
    Views:
    141
  4. RATKEN
    Replies:
    0
    Views:
    110
  5. Ambient Psychosis
    Replies:
    0
    Views:
    103
  6. Arganth
    Replies:
    0
    Views:
    118
  7. LivnLyfe
    Replies:
    0
    Views:
    123
  8. chiques
    Replies:
    2
    Views:
    201
  9. Chris Hackett
    Replies:
    0
    Views:
    137
  10. LordJavaNoob
    Replies:
    0
    Views:
    359

Share This Page

Loading...