White color not visible in toolbar - android-layout

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.

Related

Developing a simple calculator using Android Studio

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>

How to fill fully remaning space in linear layout?

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>

Relative Layout, textView not showing below button?

I've been working on my app and i've come across an issue where in the preview, whenever i place text below the button for example the "roomservice" button it doesnt show it on the emulator when running but it does in the preview. What am i doing wrong here?
This is my xml code as its the only coding part i've been working on, i've also added android:layout_below="#id/roomservice"/> in the textview but it still did not 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"
android:background="#drawable/gradient"
tools:context=".MainMenu">
<ImageButton
android:id="#+id/roomservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="95dp"
app:srcCompat="#drawable/ic_room_service_black_24dp" />
<TextView
android:id="#+id/textView"
android:layout_width="100dp"
android:layout_height="37dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="34dp"
android:layout_marginLeft="34dp"
android:layout_marginBottom="497dp"
android:text="Room Service"
android:textColor="#F8F1F5F4"
android:textFontWeight="14"
android:layout_below="#id/roomservice"/>
<ImageButton
android:id="#+id/transportation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginStart="237dp"
android:layout_marginLeft="237dp"
android:layout_marginTop="238dp"
app:srcCompat="#drawable/ic_taxi" />
<ImageButton
android:id="#+id/foodservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="239dp"
android:layout_marginLeft="239dp"
android:layout_marginTop="92dp"
app:srcCompat="#drawable/ic_restaurant" />
<ImageButton
android:id="#+id/maintenance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="234dp"
app:srcCompat="#drawable/ic_maintenance" />
<ImageButton
android:id="#+id/checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="368dp"
app:srcCompat="#drawable/ic_checkout" />
<ImageButton
android:id="#+id/baggagecollection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="234dp"
android:layout_marginLeft="234dp"
android:layout_marginTop="373dp"
app:srcCompat="#drawable/ic_bag" />
Try removing the line:
android:layout_alignParentStart="true"
from the markup for the textview. This parameter, according to the documentation, will "make the start edge of this view match the start edge of the parent". Both the TextView and The first ImageButton have the same parent (the layout), so your views could be generating on top of each other.
The 'start' position is also dependent on on the locale setting of the device. This might explain why the layout is displaying differently across devices.

Displaying a button inside a video view

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.

Need to make app's textStyle bold

I managed to make bold text by adding android:textStyle="bold" to all sections of my xml file i.e EditText, Button, TextView, etc. But is there a way to make it global so that it affects the entire application? Or do I have to always specify the fields I want bold? I hope this makes sense. Thank you.
<?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="#b5b3b3"
android:textStyle="bold"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textStyle="bold"
android:hint="Enter Text Here" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Show Items" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Items will display here"
android:color="#FFF8AA"
android:textStyle="bold"
android:orientation="vertical" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="SaveText" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Number of Items in Array" />
</LinearLayout>
If your application is using PhoneGap, you can specify the font weight in a .css file. Just attach the css to all your pages with the following code.
body
{
font-weight:bold;
}
If you're not using PhoneGap, I'm afraid I can't help you.

Resources