【问题标题】:transparent TabWidget android透明的 TabWidget android
【发布时间】:2015-05-13 11:36:12
【问题描述】:

我正在尝试使TabWidget 透明。我以编程方式尝试(在MainActivity class)但没有成功。我通过XML 尝试在蓝色 上使用Alpha(如#D9214075)。也不行

这里是 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" 
            >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dip"
                android:layout_weight="1" 
                />

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:showDividers="none"
                android:fadingEdge="none"
                android:background="#D9214075" />

        </LinearLayout>
    </TabHost>



</RelativeLayout>

这里是MainActivity 代码:

public class MainActivity extends TabActivity {
    TabHost tabHost;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        tabHost = getTabHost();  
        setTabs();
    } 

    private void setTabs()
    { 
        addTab("", R.drawable.tab_news, newss.News.class);
        addTab("", R.drawable.tab_servises, servises.Services.class);

            addTab("", R.drawable.tab_profile, profile.Profile.class);



        addTab("", R.drawable.tab_contacts, contacts.Contacts.class);
    }

    private void addTab(String labelId, int drawableId, Class<?> c)
    {
        Intent intent = new Intent(getApplicationContext(), c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
        icon.setImageResource(drawableId);      
        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }





}

【问题讨论】:

标签: android xml android-style-tabhost


【解决方案1】:

它的工作,修复activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" 
           >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" 
                />

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:showDividers="none"
                android:fadingEdge="none"
                android:layout_alignParentBottom="true"
                android:background="#D92a5094" />
        </RelativeLayout>

    </TabHost>
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2023-04-11
    • 2010-12-26
    • 2019-11-18
    相关资源
    最近更新 更多