I post my code below ,in the following layout there is a space from the top displayed in the layout. I just want to remove the top space and trying to show title at the top. But i am confused how to set it. please suggest me solution.Thanks in advance.
XML File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/folder_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="30dip"
android:textSize="15dp"
android:layout_weight="1"
android:textColor="#115c28"/>
<TextView
android:id="#+id/folder_count"
android:layout_width="0dp"
android:layout_height="60dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#115c28"
android:gravity="center"
android:paddingRight="30dip"
android:paddingLeft="35dip"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="#+id/folder_display_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
if you are just asking about the two text alignment on top without space than below code will work for you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="horizontal" >
<TextView
android:id="#+id/folder_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_weight="1"
android:gravity="top|center"
android:textColor="#115c28"/>
<TextView
android:id="#+id/folder_count"
android:layout_width="0dp"
android:layout_height="60dp"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#115c28"
android:gravity="top|center"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="#+id/folder_display_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Please check the margin values from your style.xml file inside the values directory.
It might be occupies with your Theme params.
xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!--THIS ONE FOR THE CHANGE THE COLOR OF THE APPBAR STARTS -->
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#CECFCE</item>
<item name="android:textAlignment">center</item>
</style>
<!--THIS ONE FOR THE CHANGE THE COLOR OF THE APPBAR STARTS -->
<!-- Theme : Green-->
<style name="ThemeSelector" parent="android:Theme.Light">
<item name="android:windowTitleStyle">#style/headerTextStyle</item>
<item name="android:windowBackground">#color/white</item>
<item name="android:windowTitleSize">20dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="headerTextStyle" >
<item name="android:textSize">10sp</item>
<item name="android:textColor">#color/black</item>
<item name="android:paddingLeft">10sp</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#color/light_grey</item>
</style>
<style name="myOptionMenu">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/black</item>
</style>
<!-- color -->
<color name="green">#05781e</color>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="red">#f71350</color>
<color name="grey">#666666</color>
<color name="light_grey">#bfbfbf</color>
<!-- end -->
</resources>
Related
I've been stuck with the follow issue. I have a 'normal' card view with is showing up in funny different grey colours. I don't know why.
It looks like this:
Why isn't it the normal white?
Here is the xml for the item_row
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<TextView
android:id="#+id/textViewItemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/checkBox"
android:layout_toStartOf="#+id/checkBox"
android:textColor="#000"
android:layout_centerVertical="true"
android:text="TextView" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Here is the layout_content for the activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_choose"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.apps.reuven.choosepicture.ChoosePicturesToDisplayActivity"
tools:showIn="#layout/activity_choose_to_display">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewToDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
The theme in the manifest
android:theme="#style/AppTheme">
Which is...
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Change your Theme to this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
You are using a Dark theme Theme.AppCompat.NoActionBar that's why your view background colors are showing darker.
Try using a Light theme Theme.AppCompat.Light.NoActionBar.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
If you don't want to change the theme for in case you need white toolbar icons (Back arrow, title color, overflow menu icon), you can change this behavior in your theme.
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="cardViewStyle">#style/CardView.Light</item>
</style>
I try to use selectableItemBackground in recyclerview, I test a simple demo, it's working.
Here is layout and style:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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:background="?android:attr/selectableItemBackground">
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
Style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
When I test another project, it doesn't work, I'm looking for some solutions, one of solutions say may be style.
But the solution style was Theme.AppCompat.Light.NoActionBar, i used it too.
Here is my project layout, is anyone can tell me why?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:id="#+id/image"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="0dp"
android:src="#drawable/pink_circle" />
</RelativeLayout>
</RelativeLayout>
Style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#android:color/holo_blue_dark</item>
</style>
The animation part of background requires your element to be clickable. Set android:clickable="true".
You can take a look, I think it should help: https://yq.aliyun.com/articles/12407
I am using appcompat v7 (23.1.1) for a MaterialDesign backward compability. On a API 21 device it looks nice. On older API versions nothing of my styles is affecting. Why?
Result in API 21 (goal):
Result in API 17 (bad):
Here is my style.xml inside values folder:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<!-- customize the color palette -->
<item name="android:colorPrimary">#color/teal200</item>
<item name="android:colorPrimaryDark">#color/teal500</item>
<item name="android:colorAccent">#color/material_green_A200</item>
<item name="android:statusBarColor">#color/teal500</item>
<item name="android:navigationBarColor">#color/teal500</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:colorButtonNormal">#color/button</item>
<item name="colorControlNormal">#color/deeporange300</item>
<item name="colorControlActivated">#color/deeporange500</item>
<item name="colorControlHighlight">#color/material_green_A200</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are specific to a particular API-level befor 21 can go here. -->
</style>
Here is the styles.xml inside values-v21 folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme using Material Design here. -->
<item name="android:buttonStyle">#style/button</item>
<item name="android:buttonStyleToggle">#style/togglebutton</item>
</style>
<style name="button" parent="#android:style/Widget.Material.Button">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
<style name="togglebutton" parent="#android:style/Widget.Material.Button.Toggle">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
</resources>
And here is the layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
tools:context="com.skymedium.theblowdryer.MainActivity"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/menue"
android:id="#+id/menue" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:id="#+id/row1" >
<Button
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/jukebox" />
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.5"
android:id="#+id/subrow" >
<ImageView
android:id="#+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:src="#drawable/abc_ab_share_pack_holo_dark" />
</RelativeLayout>
</LinearLayout>/
<LinearLayout
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/row2" >
<ToggleButton
android:id="#+id/onoff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:layout_marginRight="5dp"
android:layout_weight="0.7" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.3" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/swipearea" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_gravity="top"
android:src="#drawable/abc_ab_share_pack_holo_dark" />
</LinearLayout>
</LinearLayout>
I tried to set <item name="colorButtonNormal">#color/button_color</item>
It doesnt work too on older APIs.
Thanks in advance!
You have it backwards. Let me explain,
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<!-- customize the color palette -->
<!--Notice!!! No "android" prefix!-->
<item name="colorPrimary">#color/teal200</item>
<item name="colorPrimaryDark">#color/teal500</item>
<item name="colorAccent">#color/material_green_A200</item>
<item name="android:statusBarColor">#color/teal500</item>
<item name="android:navigationBarColor">#color/teal500</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:colorButtonNormal">#color/button</item>
<item name="colorControlNormal">#color/deeporange300</item>
<item name="colorControlActivated">#color/deeporange500</item>
<item name="colorControlHighlight">#color/material_green_A200</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are specific to a particular API-level befor 21 can go here. -->
</style>
styles-v21
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme using Material Design here. -->
<!--Be sure to define your colors here as well! but this time use "android:"-->
<item name="android:colorPrimary">#color/teal200</item>
<item name="android:colorPrimaryDark">#color/teal500</item>
<item name="android:colorAccent">#color/material_green_A200</item>
<item name="android:buttonStyle">#style/button</item>
<item name="android:buttonStyleToggle">#style/togglebutton</item>
</style>
<style name="button" parent="#android:style/Widget.Material.Button">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
<style name="togglebutton" parent="#android:style/Widget.Material.Button.Toggle">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
</resources>
styles.xml for < API 21 should not use the "android" prefix for your colors.
in styles.xml v-21 define your colors WITH the android prefix. The XML above should work!
i custom the Theme in android Widget.TabWidget android:tablayout
and overide the style of tabwidget in my ownway not using #android because
i want to custom my style of API 10 below same like API11+
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="AppBaseTheme" parent="android:Theme">
<!-- Window -->
<item name="android:windowNoTitle">true</item>
<item name="android:tabWidgetStyle">#style/MyTabWidget</item>
</style>
<!-- TabWidget -->
<style name="MyTabWidget" parent="android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/MyTabWidgetTextAppearance</item>
<item name="android:gravity">center|center</item>
<item name="android:tabLayout"> HOW TO CALL api_1_10_indicator.xml LAYOUT FROM MY RES LAYOUT </item>
</style>
<!-- TabWidget TextAppearance -->
<style name="MyTabWidgetTextAppearance" parent="android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#color/select_tabwidget_text_color</item>
</style>
</resources>
my res/layout/api_1_10_indicator.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="48dip"
android:layout_weight="1"
android:layout_marginStart="-3dip"
android:layout_marginEnd="-3dip"
android:background="#color/api_1_10_tab_indicator">
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
<TextView android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/tabWidgetStyle"
/>
</RelativeLayout>
if i use <item name="android:tablayout">#layout/api_1_10_indicator</item>
its not working icant call my own tablayout for the tabwidget that i custom.
HOW TO DO IT?
I have a layout that appears as follows when there is no style applied to it (other than hard-coded styles, e.g. colour & font that apply to both instances):
But it appears like this when I apply a style:
The layout is defined as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/txtBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Block Name]"
android:textSize="15sp"
android:layout_gravity="center" />
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#id/imgAlarm"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/alarm"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
and my styles.xml is defined as:
<resources>
<!-- Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. -->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
<style name="keypad_button" >
<item name="android:layout_width" >fill_parent</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >#ffffff</item>
<item name="android:gravity" >center</item>
<item name="android:textSize" >15sp</item>
<item name="android:width">65dp</item>
</style>
<!--<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">50sp</item>
<item name="android:textStyle">bold</item>
</style>-->
</resources>
What do I need to do to prevent the text from overlapping?
Change youe xml like this:
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#id/txtBlock"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
Just added android:layout_below="#id/txtBlock" to your xml
Try Linear layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Block Name]"
android:textSize="15sp"
android:layout_gravity="center" />
<Button
android:gravity="left|bottom"
android:background="#null"
android:text="[Block Status]"
android:id="#+id/btnStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgAlarm"
android:layout_alignParentLeft="true" />
</LinearLayout>
<ImageButton
android:id="#id/imgAlarm"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/alarm"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</LinearLayout>