استفاده از تگ های HTML توی لیبل ! ! !

با سلام ،

 

باز هم با inlinejava میخوایم کاری رو انجام بریم که توی b4a امکانش نیست ، استفاده از تگ های HTML توی لیبل ! ! !

 

اولین کار این کد رو به برنامه اضافه کنید :

#if java
	import android.text.Html;
	import android.widget.TextView;
    public void setHtmlText(TextView x,String y){x.setText(Html.fromHtml(y));}
#end if

و به این صورت ازش استفاده کنید ، پارامتر اول لیبل رو بدین و پارامتر دوم متن html رو  :

Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("setHtmlText",Array As Object(Label1,"<h4>Amin Shahedi</h4> <p>YAHOO98.ir.ir</p>"))

 

واسه تگ رنگ هم چون از ” استفاده میشه توی حالت عادی نمیشه استفاده کرد ولی میتونین اون رو توی فایل txt ذخیره کنید و اون رو فراخانی کنین

و یا هم میتونین به جای   ”   توی تگ ها از  ‘   استفاده کنید :

 

jo.RunMethod("setHtmlText",Array As Object(label1,"<font size='2' color='blue'>This is some text!</font>"))

 

نمونه کامل سورس :

 

#Region  Project Attributes 
	#ApplicationLabel: yahoo98.ir
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: unspecified
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
Dim label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("1")
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("setHtmlText",Array As Object(label1,"<h4>SYED esmaeil</h4> <p>YAHOO98.ir</p>"))


End Sub

#if java
	import android.text.Html;
	import android.widget.TextView;
    public void setHtmlText(TextView x,String y){x.setText(Html.fromHtml(y));}
#end if


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

 

دیدگاهتان را بنویسید