Create "forgot password" links on Android

Asked

Viewed 660 times

1

Hello, does anyone know how to create a link button to reset password as the image below, and when clicked open another Activity?

inserir a descrição da imagem aqui

2 answers

4


There are two options that solve your problem, they are: you can use a Button or a TextView.

Button

The first, which is the most common to be used, you must have come across the problem of having a background, but fortunately, solving this is also possible. You can replace the background of it with another one that is already standard android. First, you will need to define a style to your button, and this style will define how it will behave in your layout. In your case, as a button without background, but without losing the effects that a button has.

<Button
    style="?attr/borderlessButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="56dp"
    android:background="?attr/selectableItemBackground"

The code above shows us 2 important attributes, who are they style and background. The attribute style is pointing to a Resource that is present on the Android platform, that is, all Apis will have this Resource, and for each API, it will be different. In android L she has a different behavior, just like in Holo she also has another behavior.

The same goes for the attribute background, with the selectableItemBackground. It offers you a click effect (the ripple Effect). There are other options you can use, which are selectableItemBackgroundBorderless, It’s pretty much the same thing, but the click effects disperse, because it’s like the button has no edges.

You can also underline the text on your button if you need to:

forgotPassword.setPaintFlags(forgotPassword.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

Textview

Since the button inherits from the class Textview, this means that everything you have done with the button can be done with this class. That is, we can apply the style and background in the same way.

<TextView
    style="?attr/borderlessButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:background="?attr/selectableItemBackground"

As you can see, it’s exactly the same thing, but with one exception, there’s an attribute called clickable. It just points to the system that this view can be clicked on and this causes it to perform the click effects if it has one onClickListener, you can remove this attribute.

If you want to underline the text, it’s the same thing

forgotPassword.setPaintFlags(forgotPassword.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

As you can see, the use will depend on you. But I recommend that you use one Button, since it’s something standard.

Obs: when using the borderlessButtonStyle on a button, the background attribute can be removed, since it will normally behave... like a button with no edges and no background, because of the style assigned to it.

2

You first need to declare the textview in your code:

Textview telaperdeusenha = (Textview ) findviewbyid(R.id.telaperdeusenha);

then you create a click event in the textview and send it to another Activity

textviewperdeusenha.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent telaperdeusenha = new Intent(this, telaperdeusenha.class);               
            startActivity(telaperdeusenha);

        }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.