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.
Related
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 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 am very new to android designing and have some basic problems setting up a
simple layout:
Here are my goals:
I would like to have two buttons at the end of the Screen, each having the same size, filling the width of the screen.
A second LinearLayout should fill the rest of the screen, but all its content should be vertically centred.
I tried my best, but sometimes my bottom LinearLayout completely disappears, sometimes the bottom one looks fine, but the other layouts content isn't centred. I just don't know what to try out anymore. Here is what I got so far:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableName"
android:hint="#string/TableNameHint" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableDescripion"
android:hint="#string/TableDescriptionHint" />
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/TablePasswordHint"
android:id="#+id/TablePassword"
android:fontFamily="sans-serif" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:id="#+id/BtnAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnAddTable" />
<Button
android:id="#+id/BtnCancelAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnCancelAddTable"
/>
</LinearLayout>
</LinearLayout>
I tried my best, but sometimes my bottom LinearLayout completely disappears, sometimes the bottom one looks fine, but the other layouts content isn't centred.
Your button is sometimes disappearing because your top sub Linearlayout's height is match_parent, which makes it fill the parent's height and cover the below views.
What you need is a layout structure like below:
Description:
So like the description in the picture, you can set weightsum to your parent layout and set the weight percentage to your sub layout. And wrap your button's Linearlayout using Relativelayout, so that you can get the buttons centered.
Codes:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableName"
android:hint="#string/TableNameHint" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableDescripion"
android:hint="#string/TableDescriptionHint" />
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/TablePasswordHint"
android:id="#+id/TablePassword"
android:fontFamily="sans-serif" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="bottom">
<Button
android:id="#+id/BtnAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnAddTable" />
<Button
android:id="#+id/BtnCancelAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnCancelAddTable" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Update:
RelativeLayout has restrictions, it can only contain one child. So if you want to add more widgets in the bottom region then the best option for you is to use ConstraintLayout.
For Xamarin, you can follow the below steps:
Open Android SDK Manager in your VS:
Tools->Other->Check below versions of Constraintlayout and solver for Android like below and apply changes:
Install Xamrin.Android.Support.Constraint.Layout to your project through nuget package:
Then use the following xml codes:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
app:layout_constraintTop_toBottomOf="#+id/editText" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/editText2" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline"
app:layout_constraintGuide_percent="0.6"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#id/guideline"
android:orientation="horizontal">
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Short Explaination:
use android.support.constraint.Guideline with app:layout_constraintGuide_percent="0.6" to draw an invisible line to help position the buttons.(guideline will be 60% from the top screen). Then let buttons' stacklayout to be bottom of the guideline.
For detail usage of ConstraintLayout, please refer to Build responsive UI with ConstraintLayout.
Well, what you are trying to do is more achievable by just adding a Relative layout to the mix:
What you have to do is this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:layout_gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableName"
android:hint="#string/TableNameHint" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/editTableDescripion"
android:hint="#string/TableDescriptionHint" />
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/TablePasswordHint"
android:id="#+id/TablePassword"
android:fontFamily="sans-serif" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/BtnAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnAddTable" />
<Button
android:id="#+id/BtnCancelAddTable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/BtnCancelAddTable"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
RelativeLayout:
The Official Android developer website says :
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or centre).
I am writing a code with a few nested layouts. As I have used material design I also wanted to set elevation. Though elevation was working fine with the elements of outermost layout, the contents of the inner LinearLayout (nested inside a CoordinatorLayout) is not casting shadows despite setting elevation.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
android:background="#color/white"
tools:context="com.joblesscoders.aditya.todolist.HomeActivity">
<TextView
android:layout_width="match_parent"
android:id="#+id/count"
android:text="Main Activity"
android:textSize="20dp"
android:elevation="5dp"
android:textColor="#color/white"
android:gravity="center_vertical"
android:background="#color/colorPrimary"
android:layout_height="50dp" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cly"
android:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sv"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lly"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<!-- More TextViews to suit purpose -->
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/ic_add2"
app:rippleColor="#color/white"
android:id="#+id/fab"
android:layout_gravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
This code in android studio designer view produces the expected result i.e.
the TextViews displaying "Task here" have required shadows, but as soon I run it on a android 6.O custom device, the page becomes:
I would be thankful if anybody corrects me or advices on the dos and don'ts. I am extremely new to android programming, and this is my first code. So please bear with me if I have made any really very silly mistake.
I'm trying to send the white image in the back of my button and text in Relative Layout. Here is the code:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.sahni.lightspeed.starting_screen"
tools:showIn="#layout/activity_starting_screen"
android:background="#drawable/q1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textSize="70sp"
android:id="#+id/title"
android:textColor="#00e1ff"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start_button"
android:id="#+id/button"
android:textSize="20sp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="buttonOnClick"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:layout_alignLeft="#+id/title"
android:layout_alignStart="#+id/title"
android:layout_below="#+id/title"
android:background="#ffffff" />
</RelativeLayout>
The layout sets for the image aren't correct, but I don't know which ones to use to get the output I want. A screenshot of current output:
Am I using the best layout for this problem ?
Can someone please explain to me how the solution works too?
Just move to first ImageView in your RelativeLayout :
<RelativeLayout ... >
<ImageView ... />
<TextView ... />
<Button ... />
</RelativeLayout>
Your ImageView has android:layout_below="#+id/title" property so it' always below your title, so it can't be in background of your title.