[转载]Android设置TabHost的透明标签-Android开发问题解答-eoe Android开发者社区_Android开发论坛

baacloud免费翻墙vpn注册使用

[转载]设置TabHost的透明标签-Android开发问题解答-eoe Android开发者社区_Android开发论坛.

图1
图2
理想的情况应该是图1的效果,但是发现background中使用png图片默认还是会有黑色底色,请问应该如何达到透明的效果
布局如下

<!--?xml version="1.0" encoding="utf-8"?-->

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

代码如下

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
 
public class TabHostActivity extends TabActivity implements
                OnCheckedChangeListener, OnFocusChangeListener
{
        private TabHost tabHost;
        private RadioGroup tabs;
        private RadioButton btn_login, btn_register, btn_forgot;
 
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.tabhost_layout);
 
                tabs = (RadioGroup) findViewById(R.id.main_tabs);
                btn_login = (RadioButton) findViewById(R.id.tab_radio01);
                btn_register = (RadioButton) findViewById(R.id.tab_radio02);
                btn_forgot = (RadioButton) findViewById(R.id.tab_radio03);
 
                btn_login.setOnFocusChangeListener(this);
                btn_register.setOnFocusChangeListener(this);
                btn_forgot.setOnFocusChangeListener(this);
 
                tabs.setOnCheckedChangeListener(this);
 
                tabHost = getTabHost();
 
                tabHost.addTab(tabHost
                                .newTabSpec("login")
                                .setIndicator(getResources().getString(R.string.login),
                                                getResources().getDrawable(R.drawable.login))
                                .setContent(new Intent(this, LoginActivity.class)));
 
                tabHost.addTab(tabHost
                                .newTabSpec("register")
                                .setIndicator(getResources().getString(R.string.register),
                                                getResources().getDrawable(R.drawable.register))
                                .setContent(new Intent(this, RegisterActivity.class)));
 
                tabHost.addTab(tabHost
                                .newTabSpec("forgot")
                                .setIndicator(getResources().getString(R.string.forgotPass),
                                                getResources().getDrawable(R.drawable.forgot_password))
                                .setContent(new Intent(this, ForgotPassActivity.class)));
        }
 
        @Override
        public void onFocusChange(View v, boolean hasFocus)
        {
                switch (v.getId())
                {
                case R.id.tab_radio01:
 
                        break;
                case R.id.tab_radio02:
 
                        break;
                case R.id.tab_radio03:
 
                        break;
                }
        }
 
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId)
        {
                switch (checkedId)
                {
                case R.id.tab_radio01:
                        tabHost.setCurrentTabByTag("login");
                        break;
                case R.id.tab_radio02:
                        tabHost.setCurrentTabByTag("register");
                        break;
                case R.id.tab_radio03:
                        tabHost.setCurrentTabByTag("forgot");
                        break;
                }
        }
}
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏