I have an activity with the following theme
<style name="CustomDialogTitle" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/PauseDialogTitle</item>
</style>
<style name="PauseDialogTitle" parent="#android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
<item name="android:windowTitleSize">50dip</item>
<item name="android:height">70dip</item>
<item name="android:maxLines">2</item>
<item name="android:singleLine">false</item>
</style>
<style name="DialogWindowTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
</style>
and this is the custom title layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="vertical" >
<TextView
android:id="#+id/first_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="first line" />
<TextView
android:id="#+id/second_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="second line" />
I can only see one line of the title layout
What's causing the title to show only one line with fixed height ?
although i'm specifying height in the layout and style
Related
I have this Theme and want to center the title in the default toolbar. This means that I have no Toolbar in my XML file. This is what I have tried:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="actionBarTheme">#style/AppBaseTheme.Toolbar</item>
</style>
<style name="AppBaseTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:textColorPrimary">#color/colorPrimary</item>
<item name="titleCentered">true</item>
</style>
Where <item name="titleCentered">true</item> doesn't center the title. How to solve this?
In your Activity, in your onCreate()
methodgetSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM;
getSupportActionBar().setCustomView(R.layout.main_layout);
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvTitle"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFFFFF" />
I am trying to change the toolbar spinner dropdown theme strangely this is not happening. It is coming up always dark when I click on the spinner. I would like to have the background grey and text black.
I don't have any actionbar. I am setting everything through toolbar.
Hence I tried the following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:id="#+id/relativeLayoutID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="left|center"
android:text="#string/register_title"
android:textColor="#color/whiteText"
android:textSize="#dimen/text_size_medium" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:spinnerMode="dropdown"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Style xml:
<resources>
<style name="Theme.default" parent="Theme.AppCompat.Light.NoActionBar">
<item name="md_widget_color">#color/numbertext</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:windowContentOverlay">#drawable/toolbar_dropshadow</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:editTextColor">#android:color/background_dark</item>
<item name="android:textColor">#android:color/background_dark</item>
<item name="colorControlNormal">#android:color/background_dark</item>
<item name="colorControlActivated">#color/orangeText</item>
<item name="colorControlHighlight">#color/orangeText</item>
<item name="android:statusBarColor">#color/colorPrimary</item>
</style>
<style name="Widget.MyApp.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">?android:selectableItemBackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#color/blackText</item>
<item name="android:overlapAnchor">true</item>
</style></resources>
Update:
Added the following theme:
<style name="MyDarkToolbarStyle" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="background">?android:selectableItemBackground</item>
<item name="android:popupBackground">#color/layoutbackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#color/blackText</item>
<item name="android:overlapAnchor">true</item>
</style>
And applied it to the spinner:
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
style="#style/MyDarkToolbarStyle"
android:spinnerMode="dropdown"
android:visibility="gone" />
With above settings I could change the dropdown background color but not I am not able to get ripple effect on selection this used to happen before applying the theme to the spinner?
Just add the following to your Spinner the same way you did for your Toolbar:
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
So your final Spinner will look like this:
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:spinnerMode="dropdown"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone" />
I am using android studio to design a dashboard. Now I am facing the issue that I have a linear layout where I want 2 buttons in each row, with one button on the left and other at right of the screen. My xml is like this:
<LinearLayout style="#style/ActivityBody"
android:orientation="vertical"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
My style file is like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.D1t" parent="android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Theme.D1" parent="android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Theme.tranlucent" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Home">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0</item>
<item name="android:background">#fff</item>
</style>
<style name="HomeText">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textSize"> 18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/foreground</item>
</style>
<style name="TitleBar">
<item name="android:id">#id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">45dip</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#color/title_background</item>
</style>
<style name="TitleBarOperation">
<item name="android:layout_width">45dip</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="TitleBarLogo">
<item name="android:id">#id/title_logo</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="TitleBarText">
<item name="android:id">#id/title_text</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">18sp</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/title_text</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
<style name="TextBody">
<item name="android:textSize">15sp</item>
<item name="android:lineSpacingMultiplier">1.1</item>
<item name="android:textColor">#color/textBody</item>
<item name="android:textStyle">bold</item>
</style>
<style name="ActivityBody">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="DashboardButton">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:drawablePadding">2dp</item>
<item name="android:textSize">9dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#fff</item>
<item name="android:background">#null</item>
</style>
</resources
you have to use android:layout_weight
to use layout_weight you want to set layout_width as "0dp"
android:layout_width="0dp"
android:layout_weight="1"
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
what you can do is to use the relative layout and align them to left and right
below is the code
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp">
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
android:layout_alignParentRight="true"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
android:layout_alignParentLeft="true"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Option:
Use margins to the left of right button and to the right of the left button.
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dip"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
>
<Button
android:id="#+id/btnMaterialIssue"
style="#style/DashboardButton"
android:drawableTop="#drawable/materialissue"
android:text="Material Issue"
android:onClick="onGol"
layout_marginRight="20dp"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnWorkCompletion"
style="#style/DashboardButton"
android:drawableTop="#drawable/workcompletion"
android:text="Work Completion"
android:onClick="onGol"
layout_marginLeft="20dp"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Option:
place something (another view (Linearlayout)) in the middle, between the buttons.
Option:
Try to play with layout_weight
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:layout_weight="1"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:layout_weight="1"/>
</LinearLayout>
Add all linearlayout in relativelayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="horizontal" >
And in linearlayout or button add android:layout_alignParentRight="true"
<Button
android:id="#+id/btnAddExpense"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:background="#drawable/stitch_button"
android:text="#string/add" />
I have a tab widget that's appearing like follows. I need to use large images, like the image on the right, but when I do it pushes the text off the bottom of the screen. How can I get the tab button to grow 'up' rather than down?
This is the layout for the TabWidget:
<HorizontalScrollView
android:id="#+id/tabScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none"
android:layout_alignParentBottom="true"
android:layout_weight="0">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
This is the layout of the tab button:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="#dimen/tab_host_default_height"
android:orientation="vertical"
style="#style/TabAppTheme"
android:gravity="center">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="#null" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
style="#style/TabTextAppTheme" />
</LinearLayout>
This is the style (modifying minHeight doesn't do anything):
<style name="TabAppTheme">
<item name="android:paddingLeft">3dip</item>
<item name="android:paddingRight">3dip</item>
<item name="android:background">#drawable/tab_indicator_holo</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:minWidth">120dip</item>
<item name="android:minHeight">120dip</item>
</style>
<style name="TabTextAppTheme">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:maxLines">1</item>
<item name="android:maxWidth">180dip</item>
</style>
The solution was to modify the tab height here:
<resources>
<!--<dimen name="tab_host_default_height">48dp</dimen>-->
<dimen name="tab_host_default_height">64dp</dimen>
</resources>
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>