ActionBar text color

后端 未结 24 2914
日久生厌
日久生厌 2020-11-22 05:31

how can I change the text color of the ActionBar? I\'ve inherited the Holo Light Theme, I\'m able to change the background of the ActionBar but I don\'t find out what is the

24条回答
  •  天涯浪人
    2020-11-22 06:23

    This is not the recommended solution as I am going in android apis here but as my application requires to change the theme dynmically on conditions xml not possible here, So I need to do this. But This solution is working very nice.

    Solution:--

     /**
     * 
     * @author Kailash Dabhi
     * @email kailash09dabhi@gmail.com
     *
     */ 
     public static void setActionbarTextColor(Activity activity, int color) {
        Field mActionViewField;
        try {
            mActionViewField = activity.getActionBar().getClass()
                    .getDeclaredField("mActionView");
            mActionViewField.setAccessible(true);
            Object mActionViewObj = mActionViewField.get(activity
                    .getActionBar());
    
            Field mTitleViewField = mActionViewObj.getClass().getDeclaredField(
                    "mTitleView");
            mTitleViewField.setAccessible(true);
            Object mTitleViewObj = mTitleViewField.get(mActionViewObj);
    
            TextView mActionBarTitle = (TextView) mTitleViewObj;
            mActionBarTitle.setTextColor(color);
            // Log.i("field", mActionViewObj.getClass().getName());
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    
    }
    

提交回复
热议问题