介绍
介绍一个开源项目 pixate-freestyle-android
项目地址:https://github.com/Pixate/pixate-freestyle-android
让我们使用css的形式来控制Android的控件的样式,支持的控件有
使用
1.下载 JAR 包,导入工程 2.创建 default.css 在 assets 3.初始化:
Activity中:
(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// Set the license (get it for free from ).// This should be done at least once in the main activity.Pixate.setLicenseKey(“Your License Key”, “Your Email”);// Initialize pixate for the ActivityPixate.init(this);setContentView(R.layout.main);}
Fragment中
(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// Initialize pixate for the FragmentPixate.init(getActivity());setContentView(R.layout.fragment);}为控件设置样式// Setting a class for a ButtonPixate.setStyleClass(button, “myButton”);// Setting an ID for a ButtonPixate.setStyleId(button, “myButtonId”);<Buttonandroid:id=”@+id/myButtonId”class=”myButton”android:layout_width=”match_parent”android:layout_height=”wrap_content”android:text=”@string/myButtonStr”android:textSize=”16sp” />
Button
#button1:pressed {background-image: url(pressed.svg);}
CheckBox and RadioButton
/* Default state (non-checked) */#bt {background-image: url(unchecked-bg.svg);{background-image: url(checked-bg.svg);. , : {background-image: url(check-off.svg);background-size: 60;{background-image: url(check-on.svg);background-size: 60;}
ToggleButton
:{background-image: url(toggle-off.svg);background-size: 200px;{background-image: url(toggle-on.svg);background-size: 200px;}
ImageView and ImageButton
The ImageView and the ImageButton have some unique properties that can be styled via CSS.
.imageView {tint: #450022FF;transform: matrix(0.70710677, -0.70710677, 0.70710677, 0.70710677, 0.0, 200.0);scale-type: matrix;background-size: 450px;}:.imageView image {background-image: url(default.svg);background-size: 300px;, . , .{background-image: url(pressed.svg);background-size: 300px;}
ListView
Styling a ListView consists entire dividers and setting an overscroll paint:/* set a 5 pixel divider with a gradient color */.myList {divider: linear-gradient(black, orange);divider-height: 5px;}/* header and the footer */.myList overscroll {distance: 200px;footer: linear-gradient(red, white);header: url(top-overscroll.png);}Note distance that will be allowed to show them.往往教导我们大家要好好学习天天向上,要永不言弃坚持到底百折不挠宁死不屈,