-5

나는 사용자 이름 암호 로그인 버튼과 링크가되어야하는 가입 버튼으로 구성된 로그인 페이지를 만들었습니다. 이 가입 (텍스트보기)을 다음 페이지로 이동할 수있는 링크로 변환하고 싶습니다. 내가 어떻게 그럴 수 있니? 예를 들어 을 클릭하면 계정이 없습니까? sigup,안드로이드에서 링크로 textview를 변환하는 방법?

enter image description here

activity_main.xml

<RelativeLayout 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:background="@drawable/bg_gradient" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:gravity="center" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="40dp" 
      android:text="@string/welcome" 
      android:textColor="@color/white" 
      android:textSize="45dp" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_form_rounded" 
      android:orientation="vertical" > 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:background="@null" 
       android:hint="@string/email" 
       android:padding="5dp" 
       android:singleLine="true" /> 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@null" 
       android:hint="@string/password" 
       android:inputType="textPassword" 
       android:padding="5dp" /> 
     </LinearLayout> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="25dp" 
      android:background="@drawable/bg_button_rounded" 
      android:text="@string/login" 
      android:textColor="@color/white" /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="25dp" 
     android:gravity="center_horizontal" 
     android:text="@string/signup" 
     android:autoLink="web" 
     android:textColor="@color/white" /> 


</RelativeLayout> 

mainactivity.java

package com.example.internationalization12; 

import android.app.Activity; 
import android.os.Bundle; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //getActionBar().hide(); 
    } 



} 
....

이 도와주세요 .. welcome.java를 탐색한다
+2

가능한 중복 http://stackoverflow.com/questions/2734270/how-do-make-links-in-a textview-clickable) – Marius

+0

그 질문은 정말 안드로이드입니까? – luiscosta

+0

나는 android : autoLink = "web"를 추가하여 시도했다. 작동하지 않는다. – user3736518

답변

0

OnTouchListener를 TextView로 설정해야합니다.

public class MainActivity extends Activity implements View.OnTouchListener { 
     private TextView tv1; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     tv1 = (TextView) findViewById(R.id.tv1); 

     tv1.setOnTouchListener(this); 

     } 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 

     // HERE YOU HAVE TO CHECK WHICH ID IS SELECTED, IF YOU HAVE MORE THAN ONE, 
     // AND WHICH EVENT HAS THE USER DONE. 

     // IN YOUR CASE.. OPEN WEBSITE LIKE THIS: 


Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

     return true; 
     } 
    } 
+0

여러 가지 방법 중 하나 , 또한 지나치게 복잡하다. 당신의 메서드에서 여전히 motionEvent를 체크해야하기 때문에'onClick'은 훨씬 쉬울 것입니다. – Marius

+0

@Jaume Colom Ferrer 그것이 효과가 있었음을 나타냅니다. 가입을 클릭하는 동안 마우스를 어떻게 가져갈 수 있습니까? – user3736518

0

시도해 볼 수 있습니다. Linkify here

textview.setText("www.androiddeveloper.com"); 
Linkify.addLinks(textview, Linkify.WEB_URLS); 
1

이 시도 : 여기 당신에게 예를

package com.example.internationalization12; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 

public class MainActivity extends Activity { 

TextView txtSignUp; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     txtSignUp=(TextView)findViewById(R.id.txt_sign_up); 
     txtSignUp.setText(Html.fromHtml("<u>Dont have account?SignUp</u>") 
     txtSignUp.setOnClickListener(signUpListener); 
     //getActionBar().hide(); 
    } 
    public OnClickListener signUpListener=new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent(MainActivity.this,Welcome.class)); 
     } 
    }; 

} 
[? 내가 텍스트 뷰 클릭 가능한 링크를 어떻게해야합니까] (의
+0

가입을 클릭하는 동안 마우스를 올리면 어떻게 표시되는지 알려주실 수 있습니까? – user3736518

+0

아니요. android.Hover에 마우스를 올리면 이벤트가 없습니다. –

+0

위의 코드는 텍스트 아래에 밑줄을 표시하고 welcome.java로 이동합니다. –

관련 문제