android - i want to change the position of request focus error icon so that it does not shows over the toggle icon for password - android-edittext

here is my edit text xml code
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
android:theme="#style/TextLabel1">
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="#drawable/color_cursor"/>
</android.support.design.widget.TextInputLayout>
my class code for edit text
if (PassWordSignUp.length()<6) {
PassWordSignUp.setError("Your password is less than 6 characters!");
PassWordSignUp.requestFocus();
}

I was looking for an answer as well, and I got it. You can set your own drawable (which has margin) to be there instead of the red exclamation point icon.
How to make that customised icon with margin.
First, you create a new Vector Asset with the icon you would like.
Drawable -> new -> Vector Asset -> choose your icon -> Next -> Finish
Now create completely new drawable which will access the vector icon.
Plus you will now add the margin.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="32dp" //Adding the margin
android:drawable="#drawable/the_name_of_your_vector_icon"/> //Accessing the vector icon
</layer-list>
You have your XML resources. Now just display your newly (with margin) created icon instead of the normal one.
Drawable customisedErrorIcon =
getResources().getDrawable(R.drawable.your_new_error_icon);
if (customisedErrorIcon != null) {
customisedErrorIcon.setBounds(0, 0,
customisedErrorIcon.getIntrinsicWidth(),
customisedErrorIcon.getIntrinsicHeight());
}
yourEditText.setError("Error message", customisedErrorIcon);
This is how you set a customised drawable to be an error icon. And this is the result.

Related

To change the color of the spinner text font

I saw this link: https://learn.microsoft.com/en-us/xamarin/android/user-interface/controls/spinner
I want to change color of the spinner text font:
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:textColor="#FF0080FF"
android:popupBackground="#FF553232"
android:background="#FFD733D7"/>
But in the output, Color of text is always white.
Option 1. add your custom theme to style.xml. This will change the textcolor of items in the dropdown list.
<style name="MySpinnerTheme" parent="android:Theme">
<item name="android:textColor">#android:color/holo_green_dark</item>
</style>
layout
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MySpinnerTheme"
android:spinnerMode="dropdown"/>
Option 2. If you want to change the selected item only.
...
Spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
...
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e){
Spinner spinner = (Spinner)sender;
TextView textView = (TextView)spinner.SelectedView;
textView.SetTextColor(Color.Rgb(0, 235, 0));
}

Creating Xamarin button with gradient colour and curved edges

I have a xamarin Android button with curved edges (Border radius). There I want to make colour as gradient.
If I try to make it by painting the canvas (as a custom renderer) it will disappear curved edges as follows by overriding the ButtonRenderer's DispatchDraw function.
protected override void DispatchDraw(Canvas canvas)
{
var gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height,
this.StartColor.ToAndroid(),
this.EndColor.ToAndroid(),
Android.Graphics.Shader.TileMode.Clamp);
var paint = new Android.Graphics.Paint()
{
Dither = true,
};
paint.SetShader(gradient);
canvas.DrawPaint(paint);
base.DispatchDraw(canvas);
}
With the above code it button will disappear the curved edges. Before this code I was settings the color with the background property. With that property I can see the curved edges but not with the above code.
So my assumption is if I can set the gradient color for the background color property of the button this will work, unfortunately I couldn't find a way to do it.
Could someone help me to achieve this?
I find XML to be more understandable so, i would do something like this:
Gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!--make a gradient background-->
<gradient
android:type="linear"
android:startColor="#556B2F"
android:endColor="#BDB76B"
android:centerColor="#ffffff"
android:angle="90"
android:gradientRadius="90"
/>
<!--apply a border around button-->
<stroke android:color="#006400" android:width="2dp" />
<!-- make the button corners rounded-->
<corners android:radius="25dp"/>
</shape>
</item>
</selector>
Use it like this in your button xml :
android:background="#drawable/Gradient"
Or in C# code like this:
_button.SetBackgroundResource(Resource.Drawable.Gradient);

launch spinner on click of a button

I'm working on Xamarin android. I want a spinner to show up on a button click or the spinner should be on top of a button, the other way I can say. Sounds crazy but that's the stuff I got in my head a couple of days back! Yeah I've seen Spinner. May be what I'm asking is not part of the plan, but I wanna implement that!
UPDATE 2: Let me explain with an example.
Consider the Web 2.0 scientific calculator. There is a button π. You long press the button and you will get a drop down. The constant that you select from the drop down will be displayed in the textbox. I want the same functionality with the spinner. Just the difference is I want it on the button click rather than a long press. Hope I'm clear now.
That's the part of code I tried with:
<!--main.axml-->
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="#+id/myTitle">
<!--some stuff-->
<ImageButton android:onClick="onClick"
android:id="#+id/btnPi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:padding="100dip"
android:src="#drawable/pi" />
<Spinner
android:onClick="onClick"
android:id="#+id/btnConst"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:prompt="#string/cons" />
<!--And few other stuffs-->
</LinearLayout>
<!--Strings.xml-->
<string name="cons">const</string>
<string-array name="ConsArray">
<item>Angstrom star</item>
<item>Faraday constant</item>
<item>Planck constant</item>
<item>Rydberg constant</item>
<item>Stefan-Boltzmann constant</item>
<item>electric constant</item>
<item>mag. constant</item>
<item>neutron mass</item>
</string-array>
It doesn't matter's to me whether I use a Button or a ImageButton ! I'm happy with either of it. Basically I just want a drop-down menu to popup, as soon as I click that button. Can anyone help me with this? Thanks in advance.
UPDATE: When I worked on York Shen's answer , I got this blank space occupied by the spinner:
I want a spinner to show up on a button click.
You could put a Button on Spinner by using a FrameLayout :
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
<Button
android:id="#+id/bt_spinner"
android:text="Spinner Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</FrameLayout>
Then, every time your Button is click, you could use spinner.PerformClick() method to show your Spinner :
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
Effect.
Update :
I cant reproduce your problem, but here is my complete code from the document, you could use it and try again :
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
...
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format("The planet is {0}", spinner.GetItemAtPosition(e.Position));
Toast.MakeText(this, toast, ToastLength.Long).Show();
}
In your XAML, set the spinner to not be visible. In your onClick event, set change the visibility. You may have to do more in onClick if you want the things below the spinner in the linear layout to move out of the way.

YouTube Player not working with a Transparent Panel Menu Android

The YouTube Player will play videos no problem either without the transparent panel on the form or it will play them in full screen, the transparent panel has some images in it nothing special. If I take out the transparent panel, the YouTube Player works as desired, embedded in app. If I add the transparent panel to the form, this is when it will not play but in full screen. The video starts and then stops instantly. I assume it has something to do with the transparent panel but I can not understand what is happening. Any help or thoughts would be great. My java file does not change except for the initPopup would not be there. Shortened Java file version below.
XML Layout File Below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mlayout"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/spnrPSA" >
</com.google.android.youtube.player.YouTubePlayerView>
</RelativeLayout>
<com.TransparentPanel
android:id="#+id/popup_window"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="left"
android:orientation="vertical"
android:padding="1px" >
<com.TransparentPanel>
</RelativeLayout>
JAVA File Below:
public final class PSA extends YouTubeFailureRecoveryActivity{
private Animation animShow, animHide;
private YouTubePlayer player;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.psa);
initPopup();
}
private void initPopup() {
final TransparentPanel popup = (TransparentPanel) findViewById(R.id.popup_window);
// Start out with the popup initially hidden.
popup.setVisibility(View.GONE);
if (PubVars.ScreenOrientation==0){
animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
}
if (PubVars.ScreenOrientation==1){
animShow = AnimationUtils.loadAnimation( this, R.anim.l_popup_show);
animHide = AnimationUtils.loadAnimation( this, R.anim.l_popup_hide);
}
//animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
//animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
final ImageView showButton = (ImageView) findViewById(R.id.show_popup_button);
final ImageView hideButton = (ImageView) findViewById(R.id.hide_popup_button);
showButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.setVisibility(View.VISIBLE);
popup.startAnimation( animShow );
showButton.setEnabled(false);
hideButton.setEnabled(true);
}});
hideButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.startAnimation( animHide );
showButton.setEnabled(true);
hideButton.setEnabled(false);
popup.setVisibility(View.GONE);
}});
}
}
I must be missing something simple. Thanks in advance, I am fairly new to android.
Youtube Player View does not authorize overlays. Even if it's a transparent Layout(Relative, frame, ..).
The player stops the video and log into logcat some useful info. But this case is reported as "youtubeplayer is completely covered".
This api not permit anyone layer over this. "Layout is the problem"
I suggest you use the hierarchy View to see this on your layout.
I have many problems with it, because my layout stay over a little point over player.

Android align button and text in a table layout

I am trying to create a table view with a text view and a button in android. Below is my sample code ( work in progress ). As I am very new to android please help me how to arrange the text view and the button as in the image. Now I am getting button and text view. But its weird.
My Code
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
for (int i = 0; i<30; i++)
{
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView tv = new TextView(this);
Button btn=new Button(this);
tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
tv.setText("Sample Text Here");
row.addView(tv);
btn.setText("Approves");
row.addView(btn);
table.addView(row);
}
Style.xml
<style name="maxWid">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">fill_parent</item>
</style>
main_layout.xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:id="#+id/tableLayout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</TableLayout>
</ScrollView>
Expected format
Fighting with this since 1 day.. Please help
Thanks in advance!
what you can do here is create a layout xml using RelativeLayout and then add that into your TableRow.

Resources