Create "forgot password" links on Android

1

Hello, does anyone know how I can create a link button to reset password like the one in the image below, and when I click open another Activity?

    
asked by anonymous 20.08.2017 / 18:25

2 answers

4

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

  

Button

The first, which is the most common one to use, you may have come across the problem of having a background , but luckily solving this is also possible. You can replace the background with another one that is already standard for android. First, you'll need to set a style for your button, and that style will define how it will behave in your layout. In your case, like 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 above code shows us 2 important attributes , which are style and background . The style attribute is pointing to a resource that is present on the Android platform, meaning all APIs will have this resource, and for each API, it will be different. In android L has a different behavior, just as in Holo she also has another behavior.

The same is true for the background attribute, with selectableItemBackground . It gives 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 borders.

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

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

TextView

Since the button inherits from the TextView class, this means that everything you did 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 only points to the system that this view can be clicked and this causes it to perform click effects, if it has a onClickListener , you can remove this attribute.

If you want to leave the text underlined, it's the same thing

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

As you can see, usage will depend on you. But I recommend that you use Button , since it is something default.

Obs : When using borderlessButtonStyle on a button, the background attribute can be removed, since it will behave normally ... as a borderless and backgroundless button because of style attributed to it.

    
20.08.2017 / 18:50
2

You first need to declare the textview in your code:

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

After 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);

        }
    });
    
20.08.2017 / 18:32