2014-02-21 31 views
2

我是新来使用pixate样式的按钮,所以我很抱歉,如果我的问题听起来很幼稚如何使用pixate(机器人)

我想要的风格按钮,我已经创建了一个活动,并在我的资产中添加CSS文件夹,但仍然没有改变按钮。

MainActivity

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Pixate.init(this); 
    setContentView(R.layout.activity_main); 
    Button b = (Button) findViewById(R.id.button1); 
    Pixate.setStyle(b, "button.css"); 
} 

button.css

#button1 { 
background-color: linear-gradient(#FF679B,#394170); 
height: 44px; 
border-radius : 5px; 
border-width : 1px; 
border-color : #444; 
} 
+0

去这里http://www.pixate.com/blog/2013- 10-30-android-button-demo/ – insomniac

回答

1

将您在您的下一个资产文件default.css造型(其他任何文件名不会加载)。之后,你几乎没有调用setStyle(你不需要那样)。

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Pixate.init(this); 
    setContentView(R.layout.activity_main); 

    // No need to get a hold of the button. Pixate init will capture it. 
    // Just make sure you have set the id in the XML layout to "button1" 
    // Button b = (Button) findViewById(R.id.button1); 
} 

[ADDITION] 还要注意上面的评论,并检查了博客文章在http://www.pixate.com/blog/2013-10-30-android-button-demo/怎么看样式按钮的状态。 Pixate是一个开源项目,所以你可以从https://github.com/Pixate/pixate-freestyle-android(它包含了几个示例项目来帮助你开始)抓取库

+0

谢谢我会试试 – Prerak

+0

我已将button.css文件重命名为default.css,并删除了setstyle语句,但它仍然不起作用 – Prerak

+0

好的,我为你创建了一个项目,它按预期工作。您可以从https://www.dropbox.com/s/hfu3m9glhm0q58g/PixateButtonTest.zip获取zip。另外,看起来您使用的是旧版本。现在没有这样的类'Pixate'了。它被'PixateFreestyle'取代。你可以从我上面发布的github repo链接中获取最新版本。然后将其作为项目导入到您的工作区,并调整我在此处链接的项目中的库路径。 – sgibly