okey guys, i've a button like the pict below
i want to change the distance between the text with the drawable . how to trick this one ?
this is my xml code for a button
<Button
android:id="#+id/ButtonCancel"
style="#style/CAGButton"
android:drawableLeft="#drawable/selector_ic_cancel"
android:text="#string/layer_button_cancel" />
and this is the CAGButton in style.xml
<style name="CAGButton" parent="#android:style/Widget.Button">
<item name="android:drawablePadding">3dip</item>
<item name="android:textColor">#color/cag_brown</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:background">#drawable/selector_button"</item>
</style>
okey, thanks in adv. :)
Btw i solved my problem with made some changes in my button style. so it become like this :
<style name="CAGButton" parent="#android:style/Widget.Button">
<item name="android:gravity">center</item>
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:textColor">#color/cag_brown</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:background">#drawable/selector_button</item>
</style>
I think we just need to set the padding left &/ right to the best point that fit our design.
Here is the solution.
<Button
android:id="#+id/xyz"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:drawableLeft="#drawable/location"
android:drawablePadding="2dip"
android:gravity="center"
android:paddingLeft="20dip"
android:paddingRight="16dip"
android:singleLine="true"
android:text="XYZ"
android:textColor="#FFF" />
Related
I have one button and letterspacing is not working with it. Please check my following snippet code
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">#font/silka_regular</item>
<item name="android:letterSpacing">0.1</item>
<item name="android:textSize">#dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_selector_primary</item>
<item name="android:textColor">#color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">#style/ButtonText_v2</item>
</style>
layout.xml File
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="#style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
You can't apply letter spacing in button/custom button because their is some limitation in button component in which you can't make text appearance and background customization and more limitation
the solution for this is instead of button you can use text view and make custom text view it will also work similar to button and customize it according to requirement.
for example :-
https://stackoverflow.com/questions/9477336/how-to-make-a-custom-textview#:~:text=Create%20a%20Custom%20View%20for%20Textview.%20Make%20the,values%20Make%20entries%20of%20all%20fonts%20in%20strings.xml
Add android:letterSpacing in PrimaryButton_v2 it will work perfectly.
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">#font/silka_regular</item>
<item name="android:textSize">#dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_selector_primary</item>
<item name="android:textColor">#color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">#style/ButtonText_v2</item>
<item name="android:letterSpacing">0.1</item>
</style>
layout.xml File
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="#style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
I have a TextView and this is the xml code for it
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/sidelist_item_count"
style="#style/HomeTextViewItemCount"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"/>
</RelativeLayout>
And this is my Style
<style name="HomeTextViewItemCount">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/home_textview_count</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">10sp</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textColor">#android:color/white</item>
</style>
I want to make my TextView circular. This doesn't expand when there are 3 digit numbers entered. But if I remove the style attribute from the TextView and set android:background="#drawable/home_textview_count" in my text view and added rest of the attributes inside Style into my Text view. then it works as expected. Can I know why cannot we set the style and what's the mistake I have done?
Please help me.
Thank you!
How to use parent style in android xml. Code is here. its not working.
And i have added layout.xml and style.xml.
Please advise for this.
layout.xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
style="#style/textbold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Catering: "/>
<TextView
style="#style/textwhiteitalic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Veg, 20-50, Lunch, Wedding, 15 Oct, Breakfast ..."/>
</LinearLayout>
style.xml
<resources>
<style name="textbold">
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#fff</item>
</style>
<style name="textwhite">
<item name="android:textColor">#fff</item>
<item name="android:textSize">16sp</item>
</style>
<style name="textwhiteitalic" parent="#style/textwhite">
<item name="android:textStyle">italic</item>
</style>
try this you directly add parent like parent="#style/textwhite"
<style name="textwhiteitalic" parent="#style/textwhite">
<item name="android:textStyle">italic</item>
</style>
For more details go to http://developer.android.com/guide/topics/ui/themes.html
Update: try this way
<style name="txt_style_row" parent="android:Widget.TextView">
<item name="android:textColor">#fff</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">italic</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">italic</item>
</style>
and set style to your TextView like
style="#style/txt_style_row"
For this what you need to do is ::
<style name="textwhite">
<item name="android:textColor">#fff</item>
<item name="android:textSize">16sp</item>
</style>
<style name="textwhite.textwhiteitalic" >
<item name="android:textStyle">italic</item>
</style>
--
<TextView
style="#style/textwhite.textwhiteitalic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Veg, 20-50, Lunch, Wedding, 15 Oct, Breakfast ..."/>
I have a layout for a TextView and drawable as such...
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#drawable/menu6" />
<TextView
style="#style/dashboard_textview"
android:text="#string/menu6_text />
</LinearLayout>
as you can see the image uses a style attribute which looks like this
<style name="dashboard_imageview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:scaleType">fitCenter</item>
</style>
the linear layout's style surrounding it looks like this
<style name="dashboard_content_horizontal">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">3</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>
and TextView's style
<style name="dashboard_textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
</style>
this all works and looks exactly how I want it to look. however, because of this eclipse warning
"This tag and its children can be replaced by one
and a compound drawable" I decide to try to do this with just a TextView and drawable
like such..
<TextView
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu6"
android:drawableBottom="#drawable/my_drawable"
android:padding="5dp" />
this renders the image too small.. I don't see a way to apply a style to the image to get it like I want it.. anyone know the answer? is even possible?
I have a spinner, an edittext and a button in a horizontal linearlayout. When I have enter something into edittext, it increase every character and others decrease. There is an eanough blank area input but it does not change, every time it increase how long character I input.
How can I fix it?
layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/ly"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10" >
<Spinner
android:id="#+id/spinner1"
style="#style/submitspinner"
android:layout_weight="2"
android:entries="#array/a_code"
android:prompt="#string/p_code" />
<EditText
android:id="#+id/editText1"
style="#style/submitstyle"
android:layout_weight="5"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
style="#style/submitstyle"
android:layout_weight="3"
android:text="#string/btn_submit" />
</LinearLayout>
style
<style name="submitstyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">10sp</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
<item name="android:textSize">#dimen/pt</item>
</style>
<style name="submitspinner" parent="#android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">10sp</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
<item name="android:textSize">#dimen/pt</item>
</style>
I have changed style as below and it worked well...
submitstyle and submitspinner style
from
<item name="android:layout_width">wrap_content</item>
to
<item name="android:layout_width">0dp</item>
I found good tuts for this but I have closed the tab, I cannot share it...
//change you style from
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
//to
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>