日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

android tabHost

 印度阿三17 2019-07-10

我有2個關(guān)于tabHost的問題:
我用2個標(biāo)簽創(chuàng)建了tabHost
對于標(biāo)簽標(biāo)題,我使用setIndicator(TextView)
(我使用api 4級)
我的標(biāo)題背景是白色的.我使用選擇器作為標(biāo)題在標(biāo)題的差異圖像之間進(jìn)行選擇.

>我想僅在選擇/按下時使標(biāo)題文本變?yōu)榇煮w.我沒有成功使用我擁有的選擇器.我能做到嗎?我的想法是,在我使用drawable a的情況下,我想要文本粗體.其他案件不大膽.關(guān)于textColor的同樣問題.
>它看起來像一個錯誤 – 當(dāng)標(biāo)簽首次打開時,所選標(biāo)簽上的文本(我在tabHost.setCurrentTab(tabId)中使用的文本)根本看不到.在第一次按下/聚焦/聚焦任何其他項(xiàng)目后,它看起來很好.任何想法為什么或如何解決這個問題?

提前致謝

on tabActivity –

TextView title1 = new TextView(MainActivity.getInstnace(), null, android.graphics.Typeface.NORMAL);
TextView title2 = new TextView(MainActivity.getInstnace(), null, android.graphics.Typeface.NORMAL);

title1.setText("teb11 title");
title1.setBackgroundResource(R.drawable.tabtitle);
title1.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab1), null, null, null);

title2.setText("tab22 title");
title2.setBackgroundResource(R.drawable.tabtitle);

title2.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2), null, null, null);

TabSpec tab1 = mTabHost.newTabSpec("tab1").setIndicator(title1).setContent(R.id.list1);
TabSpec tab2 = mTabHost.newTabSpec("tab2").setIndicator(title2).setContent(R.id.list2);

mTabHost.addTab(tab1);
mTabHost.addTab(tab2);      
mTabHost.setCurrentTab(0);

選擇器tab1.xml

<selector xmlns:android="http://schemas./apk/res/android">  
    <item android:state_selected="true"     
    android:drawable="@drawable/iconselect"/>   
    <item android:state_pressed="true"  
    android:drawable="@drawable/iconselect"/>   
    <item android:drawable="@drawable/icon"/>        
</selector> 

tabTitle的選擇器

<selector xmlns:android="http://schemas./apk/res/android">  
    <item android:state_pressed="true"  
    android:drawable="@drawable/tabselected"/> 
    <item android:state_selected="true"     
    android:drawable="@drawable/tab" />  
    <item android:state_focused="true"  
    android:drawable="@drawable/tab" />  
</selector> 

解決方法:

對于你的問題#1:
在你的TabsAdapter上使用onPageSelected(int position),如下所示:

 public void onPageSelected(int position) {
      //your logic here
      fixTitleText();
 }

和:

 private void fixTitleText() {
      for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i  ) {
           View view = mTabHost.getTabWidget().getChildAt(i);
           TextView tv = (TextView) view.findViewById(android.R.id.title);
           tv.setTextColor(getResources().getColor(R.drawable.text_selector));
           tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
           tv.setTypeface(null, Typeface.BOLD);
      }
 }

請注意,此代碼適用于HONEYCOMB及更高版本,在此之前,選項(xiàng)卡主機(jī)視圖層次結(jié)構(gòu)略有不同

來源:https://www./content-4-314351.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多