android中TextView设置连接及关闭软键盘

事先定义好各种控件:

TextView tv;
	EditText et;
	Button btn1,btn2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tv = (TextView)findViewById(R.id.textView1);
        et = (EditText)findViewById(R.id.editText1);
        btn1 = (Button)findViewById(R.id.button1);
        btn2 = (Button)findViewById(R.id.button2);
        
        tv.setOnClickListener(this);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

设置TextView的背景图片:

        Resources res = getResources();
        tv.setBackgroundDrawable(res.getDrawable(R.drawable.a14143642a0));

在TextView中放置连接:

        String str ="请点击<a href=\"http://www.163.com\">这里</a>";
        tv.setText(Html.fromHtml(str));
        tv.setMovementMethod(LinkMovementMethod.getInstance());

设置文字的颜色及各种字体:

        //设置文字颜色
        tv.setBackgroundColor(Color.BLUE);
        //设置字体,粗体
        tv.setTypeface(Typeface.DEFAULT_BOLD);

关闭软键盘:

方法一:

		InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);  
		imm.hideSoftInputFromWindow(et.getWindowToken(), 0);//关闭软键盘

方法二:

		InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);	
		m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

今天还遇到问题一:Eclipse上的android工程显示出错,但其实文件中并没出错:

在网上的一篇博客中看到了这个问题,google官方给出的解释为:

To fix this problem, simply delete the debug.keystore file. The default storage location for AVDs is in ~/.android/avd on OS X and Linux, in C:\Documents and Settings\\.android\ on Windows XP, and in C:\Users\\.android\ on Windows Vista.
The next time you build, the build tools will regenerate a new keystore and debug key

其实就是删掉c盘当中c->User->Administer当中的.android文件当中的debug.keystore文件,然后再从新debug一下获取debug.keystore文件,具体的debug方法在我的百度空间中有详细解答:命令行下debug的具体实现。然后重启Eclipse和模拟器

问题二:按照上述步骤解决错误的android工程无法编译,出现如下所示:

[2012-09-23 22:53:47 - MyAndroid0912] Android Launch!
[2012-09-23 22:53:47 - MyAndroid0912] adb is running normally.
[2012-09-23 22:53:47 - MyAndroid0912] Performing com.lonuery.android0912.MainActivity activity launch
[2012-09-23 22:53:47 - MyAndroid0912] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'ClassPlay'
[2012-09-23 22:53:47 - MyAndroid0912] Uploading MyAndroid0912.apk onto device 'emulator-5554'
[2012-09-23 22:53:49 - MyAndroid0912] Installing MyAndroid0912.apk...
[2012-09-23 22:53:52 - MyAndroid0912] Re-installation failed due to different application signatures.
[2012-09-23 22:53:52 - MyAndroid0912] You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2012-09-23 22:53:52 - MyAndroid0912] Please execute 'adb uninstall com.lonuery.android0912' in a shell.
[2012-09-23 22:53:52 - MyAndroid0912] Launch canceled!

解决方法:将你之前所运行安装在模拟器的中这个android工程app卸载,然后重新运行,一切就都好了!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值