I've been trying to fix this issue for hours now but it looks like I'm the only one having it.
I shouldn't see the number above and below the blue line. Here is the XML
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:useDefaultMargins="true"
android:layout_margin="3dp"
app:columnCount="3"
app:rowCount="7">
........
<NumberPicker
app:layout_column="1"
app:layout_row="3"
android:id="#+id/n_of_dies"
style="#style/inputNumbers"
android:layout_width="wrap_content"
app:layout_gravity="fill_horizontal"
/>
<NumberPicker
app:layout_column="1"
app:layout_row="4"
app:layout_gravity="fill_horizontal"
android:id="#+id/carbon_content"
style="#style/inputNumbers"
android:layout_width="wrap_content"
app:layout_gravity="fill_horizontal"
/>
........
The content of Input numbers is
<style name="inputNumbers">
<item name="android:padding">10dp</item>
</style>
any ideas?
Given the problem is how you're using the paddings I'd recommend to take a look at the widget style (the Holo variation) if you want to change the default look:
...
<style name="Widget.NumberPicker">
<item name="android:internalLayout">#android:layout/number_picker</item>
<item name="android:orientation">vertical</item>
<item name="android:fadingEdge">vertical</item>
<item name="android:fadingEdgeLength">50dip</item>
</style>
...
<style name="Widget.Holo.NumberPicker" parent="Widget.NumberPicker">
<item name="android:internalLayout">#android:layout/number_picker_with_selector_wheel</item>
<item name="android:solidColor">#android:color/transparent</item>
<item name="android:selectionDivider">#android:drawable/numberpicker_selection_divider</item>
<item name="android:selectionDividerHeight">2dip</item>
<item name="android:selectionDividersDistance">48dip</item>
<item name="android:internalMinWidth">64dip</item>
<item name="android:internalMaxHeight">180dip</item>
<item name="virtualButtonPressedDrawable">?android:attr/selectableItemBackground</item>
</style>
Related
I'm trying to create a button that looks like that:
So I have created this style:
<style name="button_main" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/button_main</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
and applied this to the button:
<Button
android:id="#+id/btnConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONNECT"
style="#style/button_main"
android:drawableTop="#drawable/ic_connect"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_home" />
but this is my result:
any idea how I can add the green background to the text as well? and how can I add the white tint to the icon?
how can I add the white tint to the icon?
app:drawableTint="#color/white"
Edit:
Create separate TextView inside root layout below to button
Try This:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#color/green">
<Button
android:id="#+id/btnConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_main"
android:drawableTop="#drawable/ic_wifi_24"
app:drawableTint="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="#dimen/margin_12dp"
app:layout_constraintTop_toBottomOf="#+id/text_home" />
<TextView
android:id="#+id/tvConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
app:layout_constraintTop_toBottomOf="#id/btnConnect"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Connect"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Above code will give expected result might be you have to adjust padding n margin lil bit .
Not able to make the selected color of MaterialToggleButton to a solid color, only a transparent shade of color primary is shown.
I tried the below set of code and the out image is shown below.
Button theme in styles
<style name="ThemeButtonColorToggle" parent="AppTheme">
<item name="colorPrimary">#color/colorOrange</item>
<item name="colorButtonNormal">#color/colorOrange</item>
<item name="android:backgroundTint">#color/black</item>
<item name="strokeColor">#color/colorOrange</item>
<item name="strokeWidth">#dimen/mtrl_btn_stroke_size</item>
<item name="colorOnPrimary">#color/colorOrange</item>
<item name="colorOnPrimarySurface">#color/colorOrange</item>
</style>
XML code
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggleGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedButton="#id/btnAndroid"
app:layout_constraintTop_toBottomOf="#id/tvName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:selectionRequired="true"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/btnAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:theme="#style/ThemeButtonColorToggle"
android:textColor="#android:color/white"
android:textColorHighlight="#color/colorOrange"
android:text="Android" />
<com.google.android.material.button.MaterialButton
android:id="#+id/btniOS"
android:layout_width="wrap_content"
android:textIsSelectable="true"
android:textColor="#android:color/white"
android:theme="#style/ThemeButtonColorToggle"
android:layout_height="wrap_content"
android:text="iOS" />
</com.google.android.material.button.MaterialButtonToggleGroup>
I require to get a solid color as shown below
can anyone please help me to sort out
The background color of the MaterialButton is defined by the backgroundTint attribute.
The default value is:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_enabled="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>
You can change it in the xml layout or you can define a custom style:
<com.google.android.material.button.MaterialButton
style="#style/ButtonStyle"
.. />
with:
<style name="ButtonStyle" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#color/your_button_background_selector</item>
...
</style>
I've searched here and it doesn't seem like anyone has had this problem.
I'm following the Android Studio tutorials from here.
Basically what is happening is that my buttons look fine when I implement my XML code, but when I transfer over some of the XML code to my styles.xml and import it into my activity_main.xml file, my button changes its dimensions.
Here's my activity_main.xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16sp"
tools:context=".MainActivity"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/decreaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_minus"
android:contentDescription="#string/minus_button"
android:background="#drawable/button_background"
android:onClick="decreaseScore" />
<ImageButton
android:id="#+id/increaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_plus"
android:contentDescription="#string/plus_button"
android:layout_alignParentEnd="true"
android:onClick="increaseScore"
android:background="#drawable/button_background"/>
<TextView
android:id="#+id/score_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/initial_score"/>
<TextView
android:id="#+id/team1_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/team_1"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/decreaseTeam2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_minus"
android:background="#drawable/button_background"
android:contentDescription="#string/minus_button"
android:onClick="decreaseScore"
/>
<ImageButton
android:id="#+id/increaseTeam2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_plus"
android:contentDescription="#string/plus_button"
android:onClick="increaseScore"
android:background="#drawable/button_background"/>
<TextView
android:id="#+id/score_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/initial_score"/>
<TextView
android:id="#+id/team2_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/team_2"/>
</RelativeLayout>
</LinearLayout>
My strings.xml file.
<resources>
<string name="app_name">Scorekeeper</string>
<string name="team_2">Team 2</string>
<string name="initial_score">0</string>
<string name="plus_button">Plus Button</string>
<string name="minus_button">Minus Button</string>
<string name="team_1">Team 1</string>
</resources>
drawable.ic_minus:
<vector android:height="40dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13H5v-2h14v2z"/>
</vector>
drawable.ic_plus:
<vector android:height="40dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
drawable.button_background:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="#color/colorPrimary"/>
</shape>
I hope I have not missed anything out. If you copy paste my code inside an empty activity activity_main.xml file, you should see something like this.
Now the problem:
I want to implement some styles for my buttons. I have updated my styles.xml as such. In this case I have a parent ScoreButton which only takes the background, whereas the child elements are the plus and minus, which takes the picture and description.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="ScoreButtons" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_background</item>
</style>
<style name="PlusButtons" parent="ScoreButtons">
<item name="android:src">#drawable/ic_plus</item>
<item name="android:contentDescription">#string/plus_button</item>
</style>
<style name="MinusButtons" parent="ScoreButtons">
<item name="android:src">#drawable/ic_minus</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>
</resources>
And if I update one of my button's code as such, for instance, replacing #+id/decreaseTeam1 with the code below:
<ImageButton
android:id="#+id/decreaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
style="#style/PlusButtons"
android:onClick="decreaseScore" />
The minus button suddenly becomes inflated.
I read that child views override parent views, but I don't see how that can be a problem, since there is no change to the image size, nor have I compressed it.
The problem is that in the style definition, your ScoreButtons has Widget.AppCompat.Button as parent. This style defines a minHeight and minWidth, as follows:
<style name="Base.Widget.AppCompat.Button" parent="android:Widget">
<item name="android:background">#drawable/abc_btn_default_mtrl_shape</item>
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
So, in order to solve your problem, you just have to remove the parent from ScoreButtons style:
<style name="ScoreButtons">
<item name="android:background">#drawable/button_background</item>
</style>
You have an error in your style. You are using an ImageButton not a Button
So, you should write
<style name="ScoreButtons" parent="Widget.AppCompat.ImageButton"> // ImageButton
<item name="android:background">#drawable/button_background</item>
</style>
you are making a mistake while assigning a style. you need to use ImageButton instead of using Button.
Use this:
<style name="ScoreButtons" parent="Widget.AppCompat.ImageButton">
<item name="android:background">#drawable/button_background</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>
Instead of this:
<style name="ScoreButtons" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_background</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>
I am trying to maintain the material design ripple effect for devices with lollipop and above (21+) and stylize the button so that it doesn't have a large margin/space around it.
Example 1: Buttons with ripple effect but with margin/gap:
Example 2: Buttons with NO ripple effect and without the margin/gap:
I want the layout of Exmaple 2 with the ripple effect that is used in Example 1.
What my styles-v21 look like for Example 1 :
<?xml version="1.0" encoding="utf-8"?>
<resources>
... other styles ...
<style name="FacebookButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ff3b5998</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="GoogleButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ffdd4b39</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="TwitterButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ff55acee</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="SkipButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ffdfa800</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
</resources>
What my button layout looks like for Example 1:
<Button
android:id="#+id/login_with_facebook"
android:text="#string/login_with_facebook"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:drawableLeft="#drawable/facebook_icon"
android:drawablePadding="25dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="16.88"
android:textColor="#ffffff"
android:gravity="left|center_vertical"
android:paddingLeft="45dp"
android:theme="#style/FacebookButton" />
<Button
android:id="#+id/login_with_google"
android:text="#string/login_with_google"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:drawableLeft="#drawable/google_icon"
android:drawablePadding="25dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="16.88"
android:textColor="#ffffffff"
android:gravity="left|center_vertical"
android:paddingLeft="45dp"
android:theme="#style/GoogleButton" />
<Button
android:id="#+id/twitter_login_button"
android:text="#string/login_with_twitter"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:drawableLeft="#drawable/twitter_icon"
android:drawablePadding="25dp"
android:layout_height="45dp"
android:gravity="left|center_vertical"
android:layout_width="match_parent"
android:layout_weight="16.88"
android:textColor="#ffffffff"
android:paddingLeft="45dp"
android:theme="#style/TwitterButton" />
<Button
android:id="#+id/login_anonymously"
android:text="#string/login_anonymously"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:textColor="#ffffffff"
android:theme="#style/SkipButton" />
Any idea how I can achieve the look of Example 2 while using the ripple methodology I've presented? Any links to resources or help would be appreciated. Thanks.
Extra:
I've already read over the following
Coloring Buttons in Android with Material Design and AppCompat
How to properly style material buttons in android
You can use android:background="?android:attr/selectableItemBackground" to get a rectangular ripple.
Alternatively, you can create your own drawable. Here's the XML for the framework's selectable item background:
drawable/item_background_material.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:id="#android:id/mask">
<color android:color="#android:color/white" />
</item>
</ripple>
Here's my problem, i'm developing a news applicaiton and i used scrollview wrapping a textview to show the content of the news.
But i found that scrolling is extremly slow on android 4.0 ics when the textview is quite long, and the longer the text, the slower the scrolling is. While on android 2.3 devices things just go as fast as expected.
I don't know whether this is really a system bug cause i found this similar problems reported on the android project
Here's my layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#id/lst_news_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/list_background"
android:fadingEdge="none"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="#id/tv_news_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Detail_Title"/>
<TextView
android:id="#id/tv_news_details_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Detail_Category"/>
<TextView
android:id="#id/tv_news_details_created_at"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
style="#style/Detail_Time"/>
<include layout="#layout/detail_horizontal_divideline" />
<ImageView
android:id="#id/img_news_details_image"
style="#style/Detail_Picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/image_contentDescription"/>
<TextView
android:id="#id/tv_news_details_context"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
style="#style/Detail_Content"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dip" />
</LinearLayout>
</ScrollView>
<!-- actionbar shadow -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/action_bar_shadow"
>
</LinearLayout>
</FrameLayout>
And my style.xml
<style name="Detail_Title">
<item name="android:textColor">#color/list_item_title</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#color/list_item_text_shadow</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">2</item>
<item name="android:shadowRadius">2</item>
</style>
<style name="Detail_Category">
<item name="android:textColor">#color/list_item_category</item>
<item name="android:textSize">14sp</item>
<item name="android:shadowColor">#color/list_item_text_shadow</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">2</item>
<item name="android:shadowRadius">2</item>
</style>
<style name="Detail_Time">
<item name="android:textColor">#color/list_item_time</item>
<item name="android:textSize">14sp</item>
<item name="android:shadowColor">#color/list_item_text_shadow</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">2</item>
<item name="android:shadowRadius">2</item>
</style>
<style name="Detail_Content">
<item name="android:textColor">#color/detail_content_text</item>
<item name="android:textSize">16sp</item>
<item name="android:autoLink">all</item>
<item name="android:shadowColor">#color/list_item_text_shadow</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">2</item>
<item name="android:shadowRadius">2</item>
</style>
<style name="Detail_Picture">
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="android:background">#drawable/image_frame</item>
</style>
By the way, i've already set
android:minSdkVersion="7"
android:targetSdkVersion="14"
But haven't set the hardware accelerated flag yet.
Is there any solution? Please help me, thanks!
Well, i've found the solution on my own
just set android:hardwareAccelerated="false" in the manifest.xml
Still quite confused about the reason, waiting for an explanation.
Note that you can add the android:hardwareAccelerated="false" for a specific activity (or even a specific view) as seen here: http://developer.android.com/guide/topics/graphics/hardware-accel.html if you want to keep the rest of your app hardware accelerated.