本文主要是介绍viewPager使用AndroidChangeSkin,无痛换肤,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.引入:
implementation 'com.zhy:changeskin:4.0.2'
2.Application中去调用SkinManager.getInstance().init(this);,未来版本可能会去除该步骤。
public class MyApplication extends Application
{@Overridepublic void onCreate(){super.onCreate();****SkinManager.getInstance().init(this);****}
}
3.在需要换肤的Activity的onCreate和onDestory中,分别:
@Override
protected void onCreate(Bundle savedInstanceState)
{ SkinManager.getInstance().register(this);//...
}@Override
protected void onDestroy()
{super.onDestroy();SkinManager.getInstance().unregister(this);
}
4.布局文件,如我的:
<android.support.design.widget.TabLayoutandroid:id="@+id/mTabLayout"android:layout_width="match_parent"android:layout_height="wrap_content"****android:tag="skin:text_color:background"android:background="@color/text_color_blue"****app:tabTextColor="#ffffff"app:tabSelectedTextColor="#ff3030">
5.监听换肤的代码:
button = (Button) rootView.findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (color.equals("blue")){SkinManager.getInstance().changeSkin("red");color = "red";}elseif (color.equals("red")){SkinManager.getInstance().changeSkin("green");color = "green";}elseif (color.equals("green")){SkinManager.getInstance().changeSkin("point");color = "point";}elseif (color.equals("point")){SkinManager.getInstance().changeSkin("blue");color = "blue";}}});
效果图如下咯
这篇关于viewPager使用AndroidChangeSkin,无痛换肤的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!