سؤال

لا أعرف ما الذي فعلته ، لكن لفترة من الوقت كان لدى TabWidget علامات تبويب باللون الأبيض والتي بدت لطيفة حقًا. لم أقم أبدًا بتعيين سمة أو خلفية/لون مقدمة في مشروعي على الإطلاق. في المرة التالية التي قمت فيها بتجميعها ، عادت إلى علامات التبويب الرمادية. طلبي يستخدم السمة المظلمة الافتراضية. حتى لو قمت بتعيين موضوع التطبيق على الضوء ، فإن علامات التبويب لا تزال رمادية. من الواضح أنه كان شيئًا آخر غير لون علامات التبويب. أي شخص يعرف كيف يفعل هذا؟

هل كانت مفيدة؟

المحلول

كنت أواجه مشكلة بسبب وجود خطأ في موضوع ضوء Android 1.6 (نص مؤشر علامة التبويب أبيض). تمكنت من تجاوز السمة الافتراضية على النحو التالي:

  1. لقد قمت بإنشاء سمة مخصصة ورثت من السمة الافتراضية:

styles.xml:

<style name="MyTheme" parent="@android:style/Theme.Light">
    <item name="android:tabWidgetStyle">@style/LightTabWidget</item>
</style>

<style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
    <!-- set textColor to red, so you can verify that it applied. -->
    <item name="android:textColor">#f00</item>
</style>

ثم أقوم فقط بتطبيق هذا الموضوع على طلبي عن طريق الإضافة android:theme="@style/MyTheme" إلى <application /> عنصر بلدي AndroidManifest.xml.

نصائح أخرى

تحقق من إجابة لي: خلفية في علامة تبويب عنصر واجهة المستخدم تجاهل التحجيم

يمكنك أيضًا الرجوع إلى android.graphics.drawable صفقة

في الكود الخاص بك ، يمكنك تعيين الخلفية لعلامات التبويب مثل هذا:

tabHost.getTabWidget().getChildAt(0).setBackgroundResource(
            android.R.color.white);

في ال public void onCreate(Bundle savedInstanceState)

           `tabHost = getTabHost();
            tabHost.setOnTabChangedListener(this);
    tabHost.setCurrentTab(0);
    setTabColor();`

من المستمع:

public void ontabchanged (String tabid) {SettabColor () ؛

أخيرًا ، الوظيفة ، التي حددت المقدمة والخلفية أيضًا:

public void setTabColor() {
    // set foreground color:
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
        RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i);
        ImageView imageView = (ImageView) rl.getChildAt(0);// change it if you want it
        TextView textView = (TextView) rl.getChildAt(1);//          
        textView.setTextColor(Color.parseColor("#FFFFFF"));
    }

    // set background color:
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
        tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#010101")); // unselected
    }
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#121288")); // selected
}

في oncreated ():

    tabHost.setCurrentTab(0);

// Set tabs text color to white:
TabWidget tabWidget = tabHost.getTabWidget();
int whiteColor = getResources().getColor(R.color.white);
int someOtherColor = getResources().getColor(R.color.someOtherColor);
for(int i = 0; i < tabWidget.getChildCount(); i++){
    View tabWidgetChild = tabWidget.getChildAt(i);
    if(tabWidgetChild instanceof TextView){
        ((TextView) tabWidgetChild).setTextColor(whiteColor);
    } else if(tabWidgetChild instanceof Button){
        ((Button) tabWidgetChild).setTextColor(whiteColor);
    } else if(tabWidgetChild instanceof ViewGroup){
        ViewGroup vg = (ViewGroup)tabWidgetChild;
        for(int y = 0; y < vg.getChildCount(); y++){
            View vgChild = vg.getChildAt(y);
            if(vgChild instanceof TextView){
                ((TextView) vgChild).setTextColor(whiteColor);
            }
        }
        vg.setBackgroundColor(someOtherColor);
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top