Link einbauen? Ganz einfach :D

S

Sukama

Neues Mitglied
0
Hallo,

ich bin neu hier und hoffe, dass mir jemand dabei helfen kann.

Ich würde gerne einen Link in einer Android App einbauen.

Also sowas wie <a href="www.google.de">Jetzt zu Google</a>

Eigentlich müsste das ganz einfach sein, kann mir da jemand kurz den Code dazu geben?

Danke :)
 
Ja ist ganz einfach, z.B. bei einer TextView:
Code:
TextView textv = (TextView) findViewById(R.id.textview1);
String textviewtext = "Jetzt zu Google";
textv.setText(textviewtext);
textv.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
          String URL ="http://www.google.de";
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse(URL));
          startActivity(intent);
     }
});
Gehört eigentlich zu den Grundlagen. :confused:
Kannst du natürlich z.B. für nen Button oder was auch immer abwandeln.
 
Zuletzt bearbeitet:
naaaajaa es gibt in android doch auch diese HTML attribute für TextViews, also das du quasi einem TextView verschiedene Farben bei verschiedenen Stellen des Strings gibst usw. Ich meine da müsste auch eins für hyperlinks sein, wie genau das geht müsste aber der Threaderöffner googlen ;)

Mfg
 
In die strings.xml einfach
Code:
<string name="link">&lt;b&gt;Hello World&lt;/b&gt; This is a test of the URL &lt;a href="http://www.example.com/"&gt;Example&lt;/a&gt;</string>

Gruß

Src: Android: html in strings.xml - Stack Overflow
 
  • Danke
Reaktionen: Andy
Danke für die Antworten.

Also müsste ich folgendes bei strings einbauen:

<string name="link">&lt;b&gt;Hello World&lt;/b&gt; This is a test of the URL &lt;a href="http://www.example.com/"&gt;Example&lt;/a&gt;</string>

Und das alles in Layout, um den Hyperlink zu erstellen?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/test1"
android:linksClickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/test3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/test4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</ScrollView>
 
Neben den
Code:
 Tags hier im Forum must du dann noch deinem TextView die entsprechende xml-ressource geben. 
Das geht beim TextView bei:
[code]
<TextView
android:id="@+id/test3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
[COLOR="Red"]android:text="@string/ressourceCode"[/COLOR]
android:textAppearance="?android:attr/textAppearanceMedium"/>

Mehr infos hier

Gruß
 

Ähnliche Themen

wernho
Antworten
11
Aufrufe
694
wernho
wernho
M
Antworten
2
Aufrufe
895
maksimilian
M
R
  • Gesperrt
  • roland-senior
Antworten
2
Aufrufe
799
Fulano
Fulano
Zurück
Oben Unten