I am trying to make scrollable tabs and want to set the size of the title .How can I do this as I cant set the text size in PagerTitleStrip in the xml.Can some one tell me how to do this.
Add below style in your styles.xml
<style name="viewPagerTitleStrip">
<item name="android:textColor">#color/primary_dark_material_light</item>
<item name="android:textSize">20sp</item>
</style>
And then
<android.support.v4.view.PagerTitleStrip
android:id="#+id/pager_title_strip"
style="#style/viewPagerTitleStrip"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="top"
android:background="#color/white"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
Here is an example on how to do it:
in your xml:
<android.support.v4.view.PagerTitleStrip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/MyCustomTabText"/>
and in styles.xml
<style name="MyCustomTabText">
<item name="android:textSize">12sp</item>
</style>
Related
I have the following layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_container"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/app_name"
android:text="#string/app_name"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="#FF000000"
android:singleLine="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
I expected the layout to extend to the edges of the screen, but instead here's what I get:
The declared theme is Theme.K9Dialog:
<resources>
<style name="Theme.K9Dialog" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#drawable/popup_background</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowContentOverlay">#drawable/panel_separator</item>
</style>
Am I misunderstanding what android:layout_width is supposed to do?
This is happening because of <item name="android:windowIsFloating">true</item> in your app theme, should work fine after removing that. Also I am not why you need all those attributes like android:windowFrame and ndroid:windowAnimationStyle in your app theme. If there is no such requirement try using default app theme and add only those attributes to theme which you want to change .
I am trying to change color of home arrow indicator in custom toolbar.
There is list of examples that I found but nothing worked for me.
Here is my layout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/title_bar_toolbar_id"
app:theme="#style/ToolbarColoredBackArrow"
app:popupTheme="#style/AppTheme"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:colorControlNormal="#color/hamburger_color"
android:background="#color/custom_theme_color" >
<LinearLayout
android:id="#+id/base_title_bar_toolbar_id_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_calendar_toolbar_change_view_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_view"
android:layout_gravity="center_vertical"
android:padding="10dp" />
<TextView
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/base_title_bar_toolbar_header"
android:layout_weight="0.1"
style="#style/CustomToolBarTitleStyleBase"
android:text="#string/calendar" />
<ImageView
android:padding="13dp"
android:id="#+id/activity_calendar_toolbar_save_date_to_calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/save_date_to_calendar"
android:layout_gravity="center_vertical|start" />
<ImageView
android:id="#+id/activity_calendar_toolbar_select_semester_to_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_to_show"
android:layout_gravity="center_vertical|start"
android:padding="13dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
The styles are:
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#color/hamburger_color</item>
<item name="android:textColorPrimary">#color/hamburger_color</item>
<item name="colorControlNormal">#color/hamburger_color</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/custom_theme_color</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
<!-- Support library com`enter code here`patibility -->
<item name="background">#color/custom_theme_color</item>
<item name="titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
</style>
I tried all possibilities that I found in examples,
but nothing worked for me.
Haha, this is one of the most frustrating styling issues in Android right now...
Try creating a style like this
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorSecondary">#000000</item>
</style>
and using it in your Activity (you will probably want to merge it with your current style, as it is just the parent and this one param that matters) and of course replace the #000000 with some other color.
First of all you don't need a separate ImageView for your arrow navigation button. Just use the one from support design resources which will resize automatically according to the screen size.
Drawable upArrow = getResources().getDrawable(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(upArrow);
current layout
I have a problem related to xml layout, and I don't know how to add primary and primary dark color. Can anybody help me?
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="#+id/in"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_weight="1"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/edit_text_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"/>
<Button android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"/>
</LinearLayout>
</LinearLayout>
How it should look like
You should modify, or create if it didn't exists already the file styles.xml, in the values folder, like that :
<style name="MyMaterialTheme.Base" >
<!-- Primary Color -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/colorAccent</item>
</style>
It gets it's values from colors.xml file.
Do you mean you need to change the color of action bar located at top most position right? Then do this:
so, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11, you can change ActionBar's background color by defining custom style, as:
<resources>
<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">ANY_HEX_COLOR_CODE</item>
</style>
And, set "MyTheme" as theme for application/activity.
I'm working with android.support.design.widget.TabLayout and I'm having a REAL hardtime trying to make the applied theme to work. Here's the XML I'm trying to use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="#+id/viewPagerLayout_tabView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/TabLayout.Theme"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerLayout_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
Here's the style that is being applied:
<style name="TabLayout.Theme" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#color/rowHeaderColor</item>
<item name="tabIndicatorHeight">5dp</item>
<item name="tabTextAppearance">#style/TextAppearance.Jacksonville.Tab</item>
<item name="tabSelectedTextColor">#000</item>
</style>
<style name="TextAppearance.Jacksonville.Tab" parent="TextAppearance.Design.Tab">
<item name="android:textSize">12sp</item>
<item name="android:textColor">#4C4D4F</item>
<item name="textAllCaps">true</item>
</style>
When applied to the theme, the TextColor doesn't appear as the one I selected. I thought it was a problem with my sight so I changed it to Selected: Black and not selected: white but the same colors appeared. Is there something I would be needing to besides that in order for the theme to be applied? The problem is only with the text colors. The textAllCaps, textSize and other attributes are being applied with no major problems.
Thanks!
I have an activity layout file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/compose_message_view"
style="#style/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout style="#style/SectionContainer" >
<TextView
style="#style/FieldHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:focusable="true"
android:focusableInTouchMode="true" />
<Spinner
android:id="#+id/compose_message_department"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:prompt="#string/compose_message_department_prompt"
android:spinnerMode="dropdown" />
</LinearLayout>
<LinearLayout style="#style/SectionContainer" >
<TextView
style="#style/FieldHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:text="#string/message_account_label" />
<Spinner
android:id="#+id/compose_message_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:prompt="#string/compose_message_account_prompt"
android:spinnerMode="dropdown" />
</LinearLayout>
<EditText
android:id="#+id/compose_message_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_marginTop="16dp"
android:hint="#string/compose_message_subject_hint"
android:inputType="textCapSentences" />
<EditText
android:id="#+id/compose_message_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/compose_message_body_hint"
android:inputType="textMultiLine|textCapSentences" />
</LinearLayout>
</ScrollView>
The relevant styles look like this:
<style name="Container">
<item name="android:layout_marginRight">130dp</item>
<item name="android:layout_marginLeft">130dp</item>
<item name="android:paddingTop">32dp</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:orientation">vertical</item>
</style>
<style name="SectionContainer">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:paddingBottom">16dp</item>
</style>
<style name="FieldHeader" parent="android:Widget.TextView">
<item name="android:textAllCaps">true</item>
<item name="android:paddingLeft">12dp</item>
<item name="android:paddingTop">24dp</item>
<item name="android:paddingRight">12dp</item>
</style>
Now when I open this activity on a Nexus 7 in landscape (haven't tried other tablets yet), the ScrollView and its contents extend beyond the right edge of the screen. When I type several lines into the compose_message_body EditText so that the UI extends below the bottom of the screen, the right edge of the UI comes in to where it belongs. See screenshots below.
Any ideas as to what is going on here?
This is a side effect of using the fillViewPort attribute on your ScrollView. If you have set fillViewPort to true, then this will only be taken into account if the measured height of your child is lower than the height of your ScrollView. In that case the ScrollView will stretch the content to fill the viewport and your margins won't be applied correctly. As soon as your child's content is greater than the height of your ScrollView, your margins will be applied correctly.
I suggest to not use margins on your child layout (LinearLayout) that you have placed in the ScrollView, but only use padding.
So your Container style could become
<style name="Container">
<item name="android:paddingTop">32dp</item>
<item name="android:paddingLeft">164dp</item>
<item name="android:paddingRight">164dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:orientation">vertical</item>
</style>
In styles, your container has a margin left 130dp. Pushing your entire layout to the right by that much. If you set it to 0dp it should be in its correct position.