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" />
Related
I have a PreferenceFragmentCompat and a DrawerLayout with a NavigationView are all in my MainActivity.
I try to use ?selectableItemBackground to change my item background. It works on my TextView in NavigationView.
<TextView
android:id="#+id/feedback"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
... />
(Dark Mode: Dark grey, Light Mode: White)
But it not working in my PreferenceFragmentCompat(Always white color).
Here's my theme and I use my own layout instead the default preference layout.
My Activity Theme.
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="preferenceTheme">#style/MyPreferenceTheme</item>
</style>
<style name="MyPreferenceTheme" parent="#style/PreferenceThemeOverlay">
<item name="preferenceScreenStyle">...</item>
<item name="preferenceFragmentCompatStyle">...</item>
<item name="preferenceFragmentStyle">...</item>
<item name="preferenceCategoryStyle">...</item>
<item name="preferenceStyle">#style/MyPreferenceStyle</item>
<item name="checkBoxPreferenceStyle">...</item>
<item name="switchPreferenceCompatStyle">...</item>
<item name="preferenceCategoryTitleTextAppearance">...</item>
<item name="switchPreferenceStyle">...</item>
<item name="dialogPreferenceStyle">...</item>
<item name="editTextPreferenceStyle">...</item>
<item name="preferenceFragmentListStyle">...</item>
</style>
<style name="MyPreferenceStyle">
<item name="android:layout">#layout/preference_item</item>
</style>
My preference layout. The root is a LinearLayout.
<LinearLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:baselineAligned="false"
android:clickable="true"
android:clipToPadding="false"
android:focusable="true"
...
How can I make it work?
androidx.preference:preference:1.1.1
I have two screen. First one is main screen. There is no toolbar title which has only NavigationIcon. Second one is the other activity. It has a title and HomeAsUpIndicator. I use below style codes to remove gap between title and HomeAsUpIndicator icon in second activity.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="actionButtonStyle">#style/ActionButtonStyle</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarNavigationButtonStyle">#style/homeToolbarNavigationButtonStyle</item>
</style>
<style name="ActionButtonStyle" parent="Widget.AppCompat.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingStart">8dip</item>
<item name="android:paddingEnd">8dip</item>
</style>
<style name="homeToolbarNavigationButtonStyle" parent="#style/Widget.AppCompat.Toolbar.Button.Navigation">
<item name="android:minWidth">0dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">-20dp</item>
<item name="android:scaleType">centerInside</item>
</style>
Although there is no title in the main screen, NavigationIcon is below title when ı use this style. How can solve this problem? Yo can show in images.
I create a custom toolbar .xml and ı added my second activity .xml;
<androidx.appcompat.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_custom_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="#dimen/general_padding_left"
android:gravity="left"
android:layout_centerVertical="true">
<Button
android:id="#+id/go_back_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#drawable/ic_go_back_icon"
/>
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#color/white"/>
</LinearLayout>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
Well from your question it seems you want to hide the title in the Second activity. Correct me if I'm wrong
Use windowNoTitle attribute in styles to not show Title in toolbar.
<item name="windowNoTitle">true</item>
Alternatively, you can use setTitle(" ") in onCreate of the activity.
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 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
I want to decrease the size of the rating bar, but I'm unable to do so. I have tried to apply on rating bar still there is no change on rating bar size.
Please help
Here is style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="ratingBar" parent="#android:style/Widget.RatingBar">
<item name="android:maxHeight">10dip</item>
<item name ="android:maxWidth">10dip</item>
</style>
</resources>
main.xml
<RelativeLayout 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" >
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="58dp"
style="#style/ratingBar" />
</RelativeLayout>
You need to set the drawable for the stars
<style name="RatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars</item>
<item name="android:minHeight">32dp</item>
<item name="android:maxHeight">32dp</item>
</style>
<style name="RatingBar.Small" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars_small</item>
<item name="android:minHeight">22dp</item>
<item name="android:maxHeight">22dp</item>
</style>