2012-05-05 14 views
30

मैं अपने आवेदन उस मामले में कहना है कि आप अतिरिक्त मदद की जरूरत में कुछ पाठ है, हमें ईमेल और यहां ईमेल पता, बकवास, बकवास है कृपया।कैसे एक ईमेल पता क्लिक करने योग्य बनाने के लिए?

लेकिन मैं चाहता हूं कि वे ईमेल लिंक पर क्लिक करने और उनके ईमेल क्लाइंट को खोलने में सक्षम हों। क्या यह संभव है? या कि बुरा व्यवहार है?

यदि यह उचित व्यवहार, यह कैसे किया जा सकता है कर रहा है?

उत्तर

74

यह एक बहुत ही उचित अनुरोध है और Linkify वर्ग आप के लिए एक उपयुक्त लिंक में हर ईमेल पता हो जाएगा। बस अपने एक्सएमएल को autoLink विशेषता जोड़ें:

<TextView 
    ... 
    android:autoLink="email" /> 
+1

बेस्ट सॉल्यूशन ... स्वचालित रूप से आपके 'टेक्स्ट व्यू' में ईमेल पते पायेगा, ताकि आप चाहें तो टेक्स्ट में पैराग्राफ डाल सकें और यह स्वचालित रूप से सभी ईमेल पतों को परिवर्तित कर देगा। –

4

आप अपने onClickListener में एक इरादे पर सक्रिय होने चाहिए:

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("text/plain"); // send email as plain text 
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" }); 
intent.putExtra(Intent.EXTRA_SUBJECT, "subject"); 
intent.putExtra(Intent.EXTRA_TEXT, "mail body"); 
startActivity(Intent.createChooser(intent, "")); 
6

आप पाठ पर setOnClickListener का उपयोग कर

textView.setOnClickListener(new View.OnClickListener()); 

आप ACTION_SEND के साथ एक नया आशय बनाने के द्वारा ईमेल क्लाइंट खोल सकते द्वारा अपने पाठ क्लिक करने योग्य बना सकते हैं। Settype, ईमेल पता और इस तरह विषय:

Intent emailintent = new Intent(android.content.Intent.ACTION_SEND); 
emailintent.setType("plain/text"); 
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"[email protected]" }); 
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, ""); 
emailintent.putExtra(android.content.Intent.EXTRA_TEXT,""); 
startActivity(Intent.createChooser(emailintent, "Send mail...")); 
+0

कि इस सवाल का जवाब नहीं है, के रूप में पूरे 'TextView' क्लिक कर सकेंगे। केवल ईमेल पते का होना चाहिए। –

0

स्वीकार किए जाते हैं जवाब ईमेल के लिए काम कर सकते हैं, लेकिन यदि आप ईमेल, संपर्क नंबर, weblink की तरह अलग अलग पैटर्न का पता लगाने और इन पैटर्न के लिए क्लिक कार्यान्वयन पर एक अलग सेट करना चाहते हैं मैं आप उपयोग करना CustomClickableEmailPhoneTextview

enter image description here

नमूना कोड पुस्तकालय का उपयोग करने का सुझाव देते हैं।

CustomPartialyClickableTextview customPartialyClickableTextview= (CustomPartialyClickableTextview) findViewById(R.id.textViewCustom); 

       /** 
       * Create Objects For Click Patterns 
       */ 
       ClickPattern email=new ClickPattern(); 
       ClickPattern phone=new ClickPattern(); 
       ClickPattern weblink=new ClickPattern(); 

       /** 
       * set Functionality for what will happen on click of that pattern 
       * In this example pattern is email 
       */ 
       email.setOnClickListener(new ClickPattern.OnClickListener() { 
        @Override 
        public void onClick() { 

         Toast.makeText(MainActivity.this,"email clicked",Toast.LENGTH_LONG).show(); 


        } 
       }); 

       /** 
       * set Functionality for what will happen on click of that pattern 
       * In this example pattern is phone 
       */ 
       phone.setOnClickListener(new ClickPattern.OnClickListener() { 
        @Override 
        public void onClick() { 
         Toast.makeText(MainActivity.this,"phone clicked",Toast.LENGTH_LONG).show(); 

        } 
       }); 

       /** 
       * set Functionality for what will happen on click of that pattern 
       * In this example pattern is weblink 
       */ 
       weblink.setOnClickListener(new ClickPattern.OnClickListener() { 
        @Override 
        public void onClick() { 
         Toast.makeText(MainActivity.this,"website clicked",Toast.LENGTH_LONG).show(); 

        } 
       }); 

       /** 
       * set respective regex string to be used to identify patter 
       */ 
       email.setRegex("\\b[A-Z0-9._%+-][email protected][A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); // regex for email 
       phone.setRegex("[1-9][0-9]{9,14}"); // regex for phone number 
       weblink.setRegex("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); // regex for weblink 

       /** 
       * add click pattern to the custom textview - first parameter is tag for reference second parameter is ClickPattern object 
       */ 
       customPartialyClickableTextview.addClickPattern("email",email); 
       customPartialyClickableTextview.addClickPattern("phone",phone); 
       customPartialyClickableTextview.addClickPattern("weblink",weblink); 
2

कृपया जो करता है, तो ईमेल पते का स्थानीय भाग की तरह "[email protected]" ठीक 2 कैरेक्टर हैं स्वीकार किए जाते हैं समाधान काम नहीं करता है के बाद एपीआई 24 से थोड़ी बग के बारे में पता होना। https://issuetracker.google.com/issues/64435698

कथित तौर पर पहले से ही तय हो गई है, लेकिन जाहिरा तौर पर अभी तक शुरू नहीं:

मुद्दा देखें। (क्या आप इसे इस मुद्दे के बारे में नहीं जानते हैं और इसके अनुसार दस्तावेज़ीकरण को अपडेट करने के लिए भी परेशान नहीं हैं? https://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink)

तो जब तक आप सुनिश्चित न हों कि आप इस तरह के 2-अक्षर ईमेल से निपट नहीं रहे हैं पते, यदि आप इसके बजाय स्वीकार किए जाते हैं दृष्टिकोण यहां से समय से किया जा रहा के लिए उपयोग करना चाहिए:

TextView to send email when clicked

तो TextView से स्वत: लिंक विशेषता को दूर करने के ख्याल रखना।

संबंधित मुद्दे