Android : how can set style dynamically to component?

on Tuesday, September 9, 2014


i have used getlayoutInflater method to style a button dynamically , but width,height and weight are not applied. how can solve this problem?



in MainActivity :
award = (Button) getLayoutInflater().inflate(R.layout.btn_layout, null);
award.setId(R.id.award);
award.setText("---");
submenu.addView(award);

in inflater Layout :
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:width="0dp"
android:layout_weight="1"
style="@style/subbtn"></Button>


in style.xml :
<style name="subbtn">
<item name="android:textColor">#fff</item>
<item name="android:background">@drawable/selector</item>
</style>

0 comments:

Post a Comment