Linear Layout I can not see Password on page - android

<TextView
android:id="#+id/textView6"
android:layout_width="76dp"
android:layout_height="25dp"
android:layout_marginStart="35dp"
android:gravity="center"
android:orientation="horizontal"
android:text="Password"
android:textColor="#FFFFFF"
android:textSize="18sp"/>
I can not see Password text on the phone . I can see outside how can ı fix this?
Sorry for eng.

change android:textColor value to #000000. But better to use android:hint instead of android:text. You can also change android:hint color by android:hintColor

Actually the text is there but you can't see it because your text color is the same as the background color (which is white)
So, try changing the text color or changing the background color (or use dark mode to see your text).

If you have a problem with color and you have a single theme, you can combine day and night themes. If the user's Android phone was more than 8, only one theme will work.
I think the bad part
android:layout_height="25dp"
It can be difficult to be seen in phones of different sizes

when u wanna use TextView, try this way for me it's always working.
<TextView android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center"
android:text="Password"
android:textColor="#FFFFFF"
android:textSize="12sp"/>
so how you can see u don't need
android:layout_marginStart="35dp"
android:orientation="horizontal"

Related

Button with left icon and text perfectly aligned

Good evening,
I am developing an Android app and I am currently doing the Login interface in XML.
I am trying to create buttons with icon and text, like in the picture below :
http://i.imgur.com/J5Cj1w4.png
And here is my actual result :
http://i.imgur.com/VPALdDD.png
With this code :
<Button
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sign_up_facebook"
android:text="#string/signup_with_facebook"
android:textColor="#color/primaryTextLight"
android:drawableLeft="#drawable/ic_facebook_box_white_24dp"
android:layout_weight="0"
android:background="#drawable/button_shape_login"/>
<Button
style="?android:textAppearanceSmall"
android:layout_marginTop="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sign_up_google"
android:text="#string/signup_with_google"
android:textColor="#color/primaryTextLight"
android:drawableLeft="#drawable/ic_google_plus_box_white_24dp"
android:layout_weight="0"
android:background="#drawable/button_shape_login"/>
I am stuck at this step.
How can I get the final needed result with XML code ?
Thank you!
You can give padding to drawable like this : android:drawablePadding="50dip"
Also this question answered in this post.
Use android:drawablePadding attribute
You only need to specify android:paddingLeft attribute.
Try specifying a value of 36dp for example
The better option is to actually make the button a Relative/Linear layout with the layout set inside, the drawablePadding will not work so well with different lengths of text and buttons.
Essentially, RelativeLayout which is your button with a nested ImageView and TextView and you'll have good control of the layout, with consistent paddings around images and text within the button.
I haven't tested the following, this is essentially what you need
<LinearLayout
android:id="#+id/facebookButton"
android:layout_width="250dp"
android:layout_height="80dp"
android:orientation="horizontal">
<ImageView
android:src="#drawable/your_drawable"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"/>
<TextView
android:text="Sign up with Facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"/>
</LinearLayout>
android:gravity="center_vertical"
//use in both textView
<Button
android:paddingLeft="50dp"
android:textAlignment="textStart"
android:drawableLeft="#drawable/"
/>

A simple text is appearing on emulator but not appearing on device

I am trying a very simple application that is displaying two text field and a button (background color changed).
This is appearing fine on Emulator but when i am trying the same on actual device, one text field is not displaying and button color changed to standard color.
Any quick help ?
Regards,
Gul
XML
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/enter_phone_number"
android:id="#+id/EnterNumberMsg"
android:clickable="false"
android:visibility="visible"
android:textStyle="bold"
android:textSize="15sp"
android:textIsSelectable="false"
android:textColor="#c816365c"
android:textAlignment="center"
android:password="false"
android:background="#fa538dd5"
android:layout_centerHorizontal="true"
android:layout_below="#+id/LogoMsg"
android:layout_marginTop="100dp" />
Change your margin from 100 dp to some other low value..because as you said its not visible, size of your cell is smaller than your emulator.

Set drawable position inside button

I've got a button and a drawable on the left of the text, but I want the drawable to be closer to the text. So I need to move the drawable.
I've defined android:drawableLeft but the content of the button is not centered.
Here is my code:
<Button
android:id="#+id/addsubject"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_action_add"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="#string/addsubject"
android:textColor="#color/white"
android:background="#drawable/custombutton1" />
Here is how it looks now:
And here is how I'd like it to be:
Thank you!
Use the app:iconGravity="textStart" attribute in the MaterialButton
<com.google.android.material.button.MaterialButton
app:icon="#drawable/ic_add_24px"
app:iconGravity="textStart"
../>
If you want to reduce the padding between the icon and the text just use the app:iconPadding attribute:
<com.google.android.material.button.MaterialButton
app:icon="#drawable/ic_add_24px"
app:iconGravity="textStart"
app:iconPadding="0dp"/>
try this
<Button
android:id="#+id/addsubject"
android:layout_width="160dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:drawableLeft="#drawable/ic_action_add"
android:drawablePadding="2dip"
android:gravity="center"
android:paddingLeft="30dip"
android:paddingRight="26dip"
android:singleLine="true"
android:text="#string/addsubject"
android:textSize="13dip" />
I got this result by simply putting these properties to the button specifically
<Button
...
android:paddingLeft="60dp"
android:drawablePadding="-50dp"
android:gravity="center"
android:drawableLeft="#drawable/your_button_icon"
/>
You can tune in with your own values for your desired results.
Cheers :-)
I done this simply using paddingLeft and paddingRight. Its works!
...
android:paddingLeft="25dp"
android:paddingRight="25dp"/>
You can use LinearLayout as your button by adding OnClickListener and customize however you want.
<LinearLayout
android:layout_width="160dip"
android:layout_height="60dip"
android:orientation="horizontal"
android:background="#drawable/custombutton1">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/ic_action_add"
android:layout_gravity="center"
android:layout_weight="1"
android:scaleType="center">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/addsubject"
android:layout_gravity="center"
android:layout_weight="1"/>
</LinearLayout>
The padding between the left border of button and right border of the icon is controlled by android:paddingLeft property. The padding between the icon and the text is defined by android:drawablePadding property.
Add these two properties to you button and set the values you are happy with.
<Button
...
android:paddingLeft="24dp"
android:drawablePadding="8dp"
/>
There's also other possibilities that you want to inflate the drawable/icon programatically, after reading a while and using a lot of combination using XMLs, but still doesn't works,
You might want to fork below library instead, to suits your use-cases, such as, customizing the view, position, etc programatically, see below reference:
Drawable/icon aligned with text, see sample here
Button like facebook sign-in, see sample here
For RadioButton, see full gist code here
P.S: Copyrighted and regards to the author
for Materialbutton, you have to use the icon attribute and you can also change its tint with iconTint like this example:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="#drawable/ic_cancel"
app:iconTint="#color/black"
android:text="text" />

How do I change the text color of a Button?

How do I change the text color of a Button?
try this:
button.setTextColor(getApplication().getResources().getColor(R.color.red)); //TAKE DEFAULT COLOR
or
button.setTextColor(0xff0000); //SET CUSTOM COLOR
or
button.setTextColor(Color.parseColor("#ff0000"));
and in xml :
<Button android:id="#+id/mybtn"
android:text="text textx "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#ff0000" /> <-- SET TEXT COLOR HERE -->
Use the android:textColor property.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textColor="#android:color/white" />
button.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.red));
this work too
Use: android:textColor="#FFFFFF" on the xml configuration,
or on the activity itself by calling
button.setTextColor(0xFFFFFF);
(FFFFFF is the color white).
For more color codes: here
You can use the android textColor for foreground and for background color of button, text view or any other element see code example
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#ffb6c1"
android:textColor="#fff"
/>
any hexadecimal color code can be written for making interactive view.
change button text color programmatically
button.setTextColor(getResources().getColor(R.color.colorWhite));
An easy way to do this is by defining the color you want in res/values/colors.xml in this way:
<color name="colorCyan">#00BCD4</color>
and the button should look this way:
<Button
android:id="#+id/m_button"
android:text="MY BUTTON"
android:textColor="#color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorCyan"/>
Here's an approach with slightly less code that uses the implied Context of the current Activity.
button.setTextColor(getColor(R.color.colorPrimary));
I have not tested this with all API targets, but it is working for 28.
You can use:
button.setTextColor("green");
or
button.setTextColor(colorcode);
The format is AARRGGBB, so FF0000 is a transparent red. Use FFFF0000 instead.

android edit text making the text larger

When a user types into my edittext the text is a bit small, Id like to make this larger maybe 20-25 sp what is the best way of doing this?
I'm a big fan of starting out with system-defined values. You can always tweak things later.
<TextView style="#android:style/TextAppearance.Large" ...
Probably better in the long run to define yourself a family of styles in res/values, rather than the one-shot that I'm showing here.
Set the textSize attribute of the EditText view.
<EditText
android:textColor="#000000"
android:background="#drawable/textboxbg"
android:layout_width="726px"
android:layout_height="wrap_content"
android:inputType="none"
android:id="#+id/number"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textStyle="bold"
android:textSize="50sp"
/>
Can't you simply add a textSize attribute to your XML layout? BTW, for unit dimensions dp is preferred over sp

Categories

Resources