I have this RelativeLayout component and I want to set it to the entire screen width. How can I do that?
atendente.xml
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
style="#style/layoutAtendenteBalao"
android:id="#+atendente/rltAtendenteBalao">
styles.xml
<style name="layoutAtendenteBalao">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">210px</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_marginRight">176px</item>
<item name="android:layout_marginBottom">140px</item>
<item name="android:background">#drawable/borda_balao</item>
<item name="android:paddingLeft">15dp</item>
<item name="android:paddingRight">15dp</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
</style>
I have tried to put fill_parent to try to fill the entire width. But it does not worked. What can I do?
You should set it when you including this layout to other, like this:
<include android:id=”#+id/your_id”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”#layout/your_layout”/>
For this to work, you have to add android:layout_width , and android:layout_height in your layout node like:
<RelativeLayout
style="#style/layoutAtendenteBalao"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+atendente/rltAtendenteBalao">
use -1 and -2 for fill_parrent and wrap_content
Reference: http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT
<style name="layoutAtendenteBalao">
<item name="android:layout_width">-1</item>
<item name="android:layout_height">210px</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_marginRight">176px</item>
<item name="android:layout_marginBottom">140px</item>
<item name="android:background">#drawable/borda_balao</item>
<item name="android:paddingLeft">15dp</item>
<item name="android:paddingRight">15dp</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
</style>
Related
I am using an image button on ListView which shows a popup menu when clicked.
But the problem is that items are not visible.
This is how menu looks.I can see white text on menu in this image but on mobile screen it is invisible.
This is styles.xml
<resources>
<!-- Base application theme. -->
<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>
<item name="android:colorBackground">#color/colorPrimary</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:textColorSecondary">#fcfcfc</item>
<item name="android:actionMenuTextColor">#color/black</item>
</style>
<style name="itemTextStyle.AppTheme" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/colorPrimary</item>
</style>
<!-- LoginCreateText -->
<style name="LoginCreateText">
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_margin">2dp</item>
</style>
<!-- LoginCreateTextButton -->
<style name="LoginCreateTextButton">
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_margin">2dp</item>
<item name="android:clickable">true</item>
</style>
<style name="HintText">
<item name="android:textSize">0dp</item>
</style>
<style name="FAB">
<item name="android:layout_margin">0dp</item>
<item name="fabSize">normal</item>
<item name="rippleColor">#android:color/white</item>
<item name="backgroundTint">#color/colorAccent</item>
</style>
<style name="ListItemText">
<item name="android:textColor">#color/light_black</item>
<item name="android:textSize">#dimen/list_item_text_size</item>
<item name="android:layout_margin">2dp</item>
</style>
</resources>
This is themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Button.Login" parent="android:Widget.Button">
<item name="android:paddingLeft">18dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:textSize">#dimen/login_buttons_text_size</item>
<item name="android:layout_gravity">center</item>
<item name="android:background">#color/colorPrimary</item>
</style>
<style name="Toolbar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:itemTextAppearance">#style/itemTextStyle.AppTheme</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColorPrimary">#android:color/white</item>
</style>
<style name="CustomTheme.Dialog" parent="Theme.AppCompat.Light.Dialog"/>
</resources>
This is the menu which I am trying to display.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:popupTheme="#style/itemTextStyle.AppTheme">
<item
android:id="#+id/action_edit"
android:title="#string/action_edit" />
<item
android:id="#+id/action_delete"
android:title="#string/action_delete"/>
<item
android:id="#+id/action_assign"
android:title="#string/action_assign"
android:checkable="true"/>
<item
android:id="#+id/action_mark"
android:title="#string/action_mark"
android:enabled="false"/>
</menu>
This is layout file for Quiz Fragment.
<?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/rl_fragment_quiz_lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
app:popupTheme="#style/itemTextStyle.AppTheme"
tools:context=".ui.fragments.QuizFragment">
<include layout="#layout/single_active_list" />
<ListView
android:id="#+id/list_view_active_lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
style="#style/FAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="showAddQuizDialog"
android:src="#drawable/ic_add_quiz"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp">
<!--app:rippleColor="#android:color/white" /> -->
</android.support.design.widget.FloatingActionButton>
</RelativeLayout>
This is the layout file of the activity in which this fragment is displayed.
<?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:background="#color/grey"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Toolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Toolbar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I have tried many solutions that were asked before ( all were about toolbar menu) but none worked for me.
I defined a new style in styles.xml
<style name="itemTextStyle.AppTheme" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/colorPrimary</item>
and included it in AppTheme which didn't work.then I included it in toolbar style, menu layout, QuizFragment layout but items were still invisible.How to change the background color or item color of menu to fix this, any one will work.
Try this
style.xml
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:actionOverflowButtonStyle">#style/OverflowButton</item>
<item name="actionOverflowButtonStyle">#style/OverflowButton</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:dropDownListViewStyle">#style/PopupMenuListView</item>
<item name="dropDownListViewStyle">#style/PopupMenuListView</item>
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
<item name="actionBarDivider">#null</item>
<!-- OverFlow Menu Text Color -->
<item name="android:textColor">#color/black</item>
</style>
<!-- OverFlow menu Styles -->
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#color/black</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:background">#color/white</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<item name="android:overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">4.0dip</item>
</style>
and define theme for Activity in AndroidManifest.xml
<activity
android:name=".YourActivityName"
android:theme="#style/CustomActionBarTheme"/>
I am using only two themes files (for dark, and day)
Theme.MaterialComponents.DayNight.NoActionBar.Bridge
inside them, I have only items of the same name for both day and night, but in different colors. Found (after experimenting)...that this line is a game-changer in my case (same problem as yours) for title and menu to be white, while at the same time text on popup menu is black
<item name="android:textColorSecondary">#android:color/white</item>
here is the whole file, I used only this, and trying to not hard code anything.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Ch+++itche+++++" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<!-- Primary brand color. -->
<item name="android:textColorSecondary">#android:color/white</item>
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryVariant">#color/primaryDarkColor</item>
<item name="colorOnPrimary">#color/primaryLightColor</item>
<item name="colorOnSurface">#color/primaryColorWhiteDay</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
That is all,
Happy coding,
Nenad
Instead of setting the layout_toRightof, layout_toLeftof, layout_above and layout_below parameters everytime a view is created, is there a way to include it in the styles.xml file such that it becomes easier to implement instead of typing it every single time? This is the intended layout.
I've included my activityMain.xml and styles.xml files below.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:padding="24dp"
tools:context="com.example.android.musiclibrary.MainActivity"
android:background="#fcfcfc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
style="#style/song_group">
<ImageView
android:src="#drawable/n30_Seconds_to_Mars"
android:id="#+id/thumbnail1"
style="#style/icon"
/>
<TextView
android:layout_toRightOf="#id/thumbnail1"
android:text="Up In The Air"
android:id="#+id/song1"
style="#style/song"
/>
<TextView
android:layout_toRightOf="#id/thumbnail1"
android:text="30 seconds to Mars"
style="#style/artist"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Here's my styles.xml file
<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="icon">
<item name="android:scaleType">fitCenter</item>
<item name="android:maxWidth">42dp</item>
<item name="android:maxHeight">42dp</item>
<item name = "android:adjustViewBounds">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="song">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">6dp</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">17sp</item>
</style>
<style name="artist">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_marginLeft">6dp</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
<item name="android:textStyle">italic</item>
</style>
<style name="song_group">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:padding">10dp</item>
</style>
</resources>
I have a problem while working with List view and cardslib library.
I created a card list with the same structure of list_card_thumbnail_layout
and each card contains a photo and text
I used for card layout card_thumbnail_layout
But the source of all thumbnails is an already loaded bitmap
What I want is make the thumbnail match the width of the card and scale itself to fit inside the thumbnail
What I did is:
For card List:
<it.gmariotti.cardslib.library.view.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_cardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/list_card.thumbnail"
card:card_layout_resourceID="#layout/card_thumbnail_layout"
/>
For indivisual Card:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<it.gmariotti.cardslib.library.view.component.CardThumbnailView
style="#style/card_thumbnail_outer_layout"
android:id="#+id/card_thumbnail_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- Main Content View -->
<FrameLayout
android:id="#+id/card_main_content_layout"
style="#style/card.content_outer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
and in styles:
<style name="card_thumbnail_image">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="android:scaleType">centerCrop</item>
</style>
<style name="card_thumbnail_outer_layout">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
I don't know where the problem is. :(
I think the attribute 'adjustViewBounds' is the answer in this case
give this a try:
<style name="card_thumbnail_image">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="android:scaleType">centerInside</item>
<item name="android:adjustViewBounds">true</item>
</style>
I have styles
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="TextStyle" >
<item name="android:textSize">8sp</item>
<item name="android:textColor">#0A0A0A</item>
<item name="android:typeface">serif</item>
</style>
<style name="TextStylePressed" >
<item name="android:textSize">18sp</item>
<item name="android:textColor">#0A0A0A</item>
<item name="android:typeface">serif</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#C2C2C2</item>
</style>
</resources>
and I use selector arrow.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#style/TextStylePressed" android:state_selected="true"/>
<item android:drawable="#style/TextStylePressed" android:state_pressed="true"/>
<item android:drawable="#style/TextStylePressed" android:state_focused="true"/>
<item android:drawable="#style/TextStyle" />
</selector>
The problem is that I can not understand - if it works?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#drawable/arrow" // <---- Framed here
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/arrow" // <---- then here
android:orientation="vertical" >
</LinearLayout>
Consequently, after all attempts nothing happens
AFAIK selectors can only be defined to select a drawable and not any other attribute. If you check the doc , it compiles to StatelistDrawable, So i believe it can only be used for drawables
i need to implement an application in android using styles. I know that, difining an style for each object in styles.xml, it's possible to stablish diferent styles for: Textview, Buttons, editviews..but in the special case of spinner it doesn't work. this is my example:
this is the layout main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
style="#style/TextviewVerde"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/escribenombre"
/>
<EditText
style="#style/EditviewAzul"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/TxtNombre"
/>
<Spinner
style="#style/SpinnerRojo"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/TxtSpinner"
android:prompt="#string/seleccionetexto"
/>
<Button
style="#style/BotonBlanco"
android:id="#+id/BtnHola"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pulse aqui"
/>
</LinearLayout>
and this is the styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextviewVerde" >
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">5pt</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="TextviewRosa" >
<item name="android:textColor">#5F04B4</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">15pt</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="EditviewAzul" >
<item name="android:textColor">#0000FF</item>
<item name="android:textSize">8pt</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:shadowColor">#0000FF</item>
</style>
<style name="SpinnerRojo" >
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#DF0101</item>
<item name="android:gravity">center</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">11pt</item>
<item name="android:drawSelectorOnTop">true</item>
</style>
<style name="BotonBlanco">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">12pt</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:clickable">true</item>
</style>
</resources>
every object works well, but the spinner doesn't change its appearance. My boss told me that i have to implement styles without changing the *.java file, what can i do?? i need to change the colour of the spinner options, the backgound, add some pics.. etc. thanks a lot for the help
http://www.mokasocial.com/2011/03/easily-create-a-default-custom-styled-spinner-android/
To make custom styled dropdown when the spinner is clicked, you should create a custom Adapter with a reference to your layout xml defining the rows of the list.
For example:
String[] elements = {"optionA", "optionB"};
Spinner s = (Spinner) findViewById(R.id.your_spinner_id);
ArrayAdapter adapter = new ArrayAdapter<String>(this,
R.id.textViewId, elements);
adapter.setDropDownViewResource(R.layout.your_dropdown_layout);
Where textViewId should be a child view in your_dropdown_layout.
Hope that helped.
Ripityom