我有TextView文本,动态更改.这个文本包含像<a href='myWord'>myWord</a>.我希望在点击这个"链接"之后,myWord出现在同一活动的EditText中.
这是我的代码:
txt.setText(Html.fromHtml("...<a href='link'>link</a>..."));
txt.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
它适用于href属性中的URL,但是另一种格式存在错误.
我在StackOverflow上发现了很多类似的问题,但所有问题都与url链接有关.在我的应用程序中,我想在活动中创建"链接".一般来说,如果依赖,我可以将标签更改为其他标签...
请帮我!谢谢!
-----已解决-----谢谢雅各布菲利普斯的想法!
将来可能会有人感兴趣.这是一个代码:
//This is my string;
String str = "<b>Text</b> which contains one <a href='#'>link</a> and another <a href='#'>link</a>";
//TextView;
TextView txt = new TextView(this);
//Split string to parts:
String[] devFull = data[v.getId()][1].split("<a href='#'>");
//Adding first part:
txt.append(Html.fromHtml(devFull[0]));
//Creating array for parts with links (they amount always will devFull.length-1):
SpannableString[] link = new SpannableString[devFull.length-1];
//local vars:
ClickableSpan[] cs = new ClickableSpan[devFull.length-1];
String linkWord;
String[] devDevFull = new String[2];
for(int …Run Code Online (Sandbox Code Playgroud) 我需要在我的应用程序中播放一个简短的声音.我写了下面的代码,但我的三星手机上没有声音和奇怪的振动.但同时这段代码在我的android模拟器上运行良好.我的代码是:
package com.samplers;
import android.app.Activity;
import android.media.SoundPool;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class FixVibroActivity extends Activity {
/** Called when the activity is first created. */
private Button white;
private SoundPool spool;
private int soundID;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID = spool.load(this, R.raw.error, 1);
white = (Button)findViewById(R.id.whiteBtn);
white.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound();
}
});
}
public void Sound(){
AudioManager audioManager = …Run Code Online (Sandbox Code Playgroud) 我将Google Play服务库添加到了我的应用程序中.一切正常,但我的apk的大小在4(!)倍从350KB增加到1.6MB.要从Google Play服务库中删除未使用的类,我决定使用ProGuard.但是现在我无法运行项目或将其导出到apk,因为ProGuard返回错误.当我不使用GPS lib时我没有出口问题,但我不能用这个库创建apk.我读了很多关于这个问题的内容,但我找到的任何解决方案都没有帮助我.
这是我的proguard-project.txt(在这里推荐)
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
Run Code Online (Sandbox Code Playgroud)
这是我的proguard.cng
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public …Run Code Online (Sandbox Code Playgroud) 我的EditTextAndroid应用中有一个视图.我需要"内部链接",这意味着我需要一些按钮或跨越内部EditText,onClick我可以执行一些操作(不重定向到网页).我用ClickableSpan()这样的方式实现了这个按钮
linkWord = "my link";
link = new SpannableString(linkWord);
cs = new ClickableSpan(){
private String w = linkWord;
@Override
public void onClick(View widget) {
wrd.setText(w);
}
};
link.setSpan(cs, 0, linkWord.length(), 0);
et.append(link);
Run Code Online (Sandbox Code Playgroud)
为了使这个跨度可点击我使用
et.setMovementMethod(LinkMovementMethod.getInstance());
"内部链接"工作正常,但使用et.setMovementMethod()复制和粘贴项目后禁用OnLongClick菜单.这是一个问题,因为我需要"链接" EditText并同时复制此视图中的文本.
我有想法设置监听器的OnLongClickListener东西,如removeMovementMethod()临时禁用"链接"功能和使用菜单与复制/粘贴和再次处理文本切换setMovementMethod()方法后.但我不知道如何实现这一点.
你能帮助我吗?你可能还有另外一些方法......
谢谢!
我徘徊是Zend Framework中图像大小调整的一些特殊工具?或者我应该使用这样的代码:
$upload = new Zend_File_Transfer_Adapter_Http();
try {
$upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
}
$im_org = imageCreateFromJpeg($upload);
$im_bg = imageCreateTrueColor(300, 300);
imageCopyResampled($im_bg, $im_org, 0, 0, 0, 0, 300, 300, imageSX($im_org), imageSY($im_org));
imageJpeg($im_bg, "pict/" . $id . "_bg.jpg", 100);
imagedestroy($im_org);
imagedestroy($im_bg);
Run Code Online (Sandbox Code Playgroud)
谢谢!