How will I display a button inside a video view with the android studio? The button seems to be there but not visible.
<RelativeLayout>
<VideoView
android:id="#+id/vV"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
<Button
android:id="#+id/btn"
android:text="btn"/>
</RelativeLayout>
I want the button to appear visible in the video view. The button is clickable but not visible
Use Constrain layout by adding
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
to your gradle
<?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"
android:background="#color/colorbackground">
<VideoView
android:id="#+id/videoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
</android.support.constraint.ConstraintLayout>
you can simply use this inside button:
android:background="#00DAEDCC"
this will make your button transparent. I think, it will help you.
Related
My design layout in android studio is missing after i add FragmentContainerView. Its worrking fine before, but after a while this happen. How to fix it?
here is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="#color/blue"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/img" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="com.DStudio.Finjer.MainFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp"
android:background="#drawable/rectangle_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<com.google.android.gms.ads.AdView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
In the error panel there must be an option to "suppress the warning for this session". Once you do that your layout will show.
Back button disappear even though i called layout below the recycler view, I can show the button if i set the height manually but i need to use "wrap_content" because not all devices have the same size. Im trying to add a back button on the bottom after the recycler view. pls help on why it dosent show.. Im new in android studio ive tried changing the layouts but dosent work..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity"
android:background="#color/colorLight">
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/search_view_bg"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:queryHint="Search"
android:iconifiedByDefault="false"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/viewMain"
android:layout_below="#id/searchView"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<Button
android:id="#+id/back"
android:layout_width="187dp"
android:layout_height="50dp"
android:text="Go Back"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:layout_below="#id/viewMain"
android:textSize="14sp"
android:fontFamily="#font/varela_round"
android:layout_centerHorizontal="true"
android:background="#drawable/round_back_white"
/>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/searchView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/viewMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
</androidx.recyclerview.widget.RecyclerView>
<Button
android:id="#+id/back"
android:layout_width="187dp"
android:layout_height="50dp"
android:layout_below="#id/viewMain"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/round_back_white"
android:fontFamily="#font/varela_round"
android:text="Go Back"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
#xenxen101219 After SearchView Use NestedScrollView
I am trying to develop a simple calculator which has only add and subtraction functions using Andriod Studion. But when I run it all the elements are overlapping. I have attached a screenshot to get more clear idea about my problem. I really appreciate if anyone can tell me why I got this and how to fixed it.
screenshot
Actually you are not using the layouts properly. I will suggest you
to learn the layouts properly then you will not face such issues.
Thank you.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
tools:context=".ui.activities.MainActivity">
<TextView
android:id="#+id/text1"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="#string/first_number" />
<EditText
android:id="#+id/editText1"
android:layout_width="250dp"
app:layout_constraintTop_toBottomOf="#id/text1"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/text2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/second_number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText1"
/>
<EditText
android:id="#+id/editText2"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/text2"
android:hint="Enter First Number" />
<TextView
android:id="#+id/text3"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText2"
android:text="#string/answer" />
<EditText
android:id="#+id/editText3"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/text3"
android:hint="Enter First Number" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
android:layout_weight="0.5"
android:layout_marginTop="80dp"
app:layout_constraintTop_toBottomOf="#id/editText3"
app:layout_constraintStart_toStartOf="parent"
android:background="#color/colorPrimary"
/>
<Button
android:id="#+id/btn2"
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/btn1"
android:background="#color/colorPrimary"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
I have a problem with layout in my app that I am writing. I want to make some domestic changes like buttons to be in one column and they should be on right hand side. Additionally EditText with Buttons should be around middle of the screen ( I attach screenshot of how it looks for now). After reading few of similar problems the main idea was to modify textView1 on layout_width="fill_parent", but that doesnt make any difference. Most of changes that I am trying doesnt seems to have any effect, do you know why ?Current Layout
I am also giving the adapter view layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<TextView
android:gravity="center"
android:text="TextView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/textView1"
android:textSize="18sp"
android:layout_weight="66.6"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="33.3">
<Button
android:id="#+id/removeBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_remove"
android:backgroundTint="#color/black" />
<EditText
android:id="#+id/itemAmount"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:inputType="number"
android:minEms="1"
android:text="1"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#android:color/black"
android:textSize="20sp" />
<Button
android:id="#+id/addBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_add"
android:backgroundTint="#color/black" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_marginLeft="60dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:clickable="true"
app:fabCustomSize="40dp"
app:srcCompat="?android:attr/textCheckMarkInverse" />
</LinearLayout>
</LinearLayout>
I have a green toolbar in my layout and I inserted a textview into it to center the text horizontally. I want the text of the toolbar to be white and I choose the color white for that. However, the white text is barely visible. Can anyone help? I'd appreciate it.
Here is the XML code of the TextView:
<?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"
tools:context=".MainActivity"
tools:ignore="ExtraText">
'<!--Learning: The following lines define a toolbar -->'
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_mainActivity"
android:layout_width="match_parent"
android:layout_height="53dp"
android:background="#435cb53f"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#android:color/holo_green_light" />
<Button
android:id="#+id/Bestellen_Button"
android:layout_width="255dp"
android:layout_height="96dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/Bestellen_Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.584"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.461" />
<Button
android:id="#+id/Statistik_Button"
android:layout_width="256dp"
android:layout_height="95dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/Statistik_Button"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.875" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="147dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="80dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="80dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#android:color/transparent"
android:contentDescription="Test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.744"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.203"
app:srcCompat="#mipmap/ic_launcher_round" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="153dp" />
<TextView
android:id="#+id/textView_ToolBar_MainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TestText"
android:textColor="#android:color/white"
android:textSize="24sp"
android:visibility="visible"
app:fontFamily="#font/roboto_bold"
app:layout_constraintBottom_toBottomOf="#+id/toolbar_mainActivity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.535"
app:layout_constraintStart_toStartOf="#+id/toolbar_mainActivity"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.421"
tools:text="TestText" />
</android.support.constraint.ConstraintLayout>
I feel the reason why it's happening is due to elevation. Since the elevation of the Toolbar is 4dp, it is above the textView.
I guess if you add android:elevation="4dp" or anything more than 4dp, you will be able to see the text clearly.
Good luck.
The problem is the elevation you are using in your toolbar. This means, the toolbar is lying "on top" of the rest, therefore overlying the TextView. And this means that the text is not showing as you want it to.
Solution 1
Get rid of the elevation altogether and your text will show in plain white.
Solution 2
I think it should also work if you put both, the toolbar and the TextView into another Layout within your ConstraintLayout (e.g. into a RelativeLayout) and add the elevation to that layout instead of the toolbar. This way both of the elements should have the same elevation without casting a shadow upon each other. But I'm not entirely sure about this solution, you'll have to try it to see if it works.
Here is some additional information about elevation.