I am using actionbar and displaying some title and subtitle of the actionbar. I want the size of subtitle to be smaller than the title. And also I have a logo icon in left. So how should I adjust the alignment.
There's an another fragment in which I am using back button as home button. So, I also want to reduce the space between the back button and the Title of actionbar.
I tried using this code. But it didn't help.
UserListFragment.java
View viewActionBar = getActivity().getLayoutInflater().inflate(R.layout.actionbar_layout, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,ActionBar.LayoutParams.MATCH_PARENT,Gravity.CENTER);
TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.mytext);
textviewTitle.setText("DemoIosAppDoctor"+"\n"+"Doctor");
actionBar.setCustomView(viewActionBar, params);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
actionbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:id="#+id/mytext"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="-2dp"/>
</LinearLayout>
To completely customise Actionbar, you should define Toolbar in design XML and add you own component there. and, then use like this
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(tb);
Use XML like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Note: You have to set this activity theme as NoActionBar like this:
<activity
android:name=".YourActivity"
android:parentActivityName=".index.IndexActivity"
android:theme="#style/AppTheme.NoActionBar" />
And theme like this:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Related
I need to change the font size, the font itself, and center the text in the ToolBar.
I took a template from Bottom Navigation Activity studio.
I was trying setting the text size in themes.xml (I was able to change the background color and text color there)
<style name="CustomToolBarStyle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="titleTextColor">#color/black</item>
<item name="android:background">#color/white</item>
I was trying to use this option in themes.xml:
<item name="android:gravity">center</item>
It didnt help. I tried to follow this instruction:
https: //stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font Throws android.support.v7.widget.Toolbar into an error and get a crash.
ToolBar
NavbarTemplate
For API level 21+ you can use app:titleTextAppearance property of toolbar
<android.support.v7.widget.Toolbar
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="?actionBarSize"
android:id="#+id/toolbar"
app:titleTextAppearance="#style/yourstyle" />
and override the default title size in a custom style:
<style name="yourstyle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">yourFont</item>
</style>
For centering, you should follow this answer and if this and none of the other answer works for you from the same post https://stackoverflow.com/a/38175403/9917400, than just use a linear layout inside Toolbar.
You can set constraint-layout inside the toolbar
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:textColor="#color/blue"
android:textSize="16sp"
app:fontPath="fonts/xxx" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
If you're using androidx don't use android.support.v7.widget.Toolbar.
You have to use androidx.appcompat.widget.Toolbar.
Create toolbar.xml in res/layout.
Put this code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="yourToolBarBackgroundColor"
>
<TextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TestToolBar"
android:fontFamily="yourFont"
android:textSize="yourSizeOfText"
android:textColor="yourTextColor" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/activity_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Disable ActionBar in themes.xml:
<style name="Theme.YourProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
For night theme you have to do same thing in themes.xml(night)
Then in MainActivity.java in onCreate:
setContentView(R.layout.toolbar);
I am trying to make my first hamburger menu with some images, but they are displayed in grey scale, not the real image. Here is a photo of how it looks:
And here is the code for the XML file:
<item
android:id="#+id/desp_mercedes"
android:icon="#drawable/mercedes"
android:title="Mercedes" />
<item
android:id="#+id/desp_audi"
android:icon="#drawable/audi"
android:title="Audi" />
<item
android:id="#+id/desp_bmw"
android:icon="#drawable/bmw"
android:title="BMW" />
I want to know how to display the original images. I have both SVG and PNG files for better quality.
In your nav_header_main.xml layout resource file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_header"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#color/colorAccent"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
//here you can add your image src
<ImageView
android:id="#+id/nav_header_imageView"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="#drawable/ic_imageview" />
<TextView
android:id="#+id/nav_header_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:text="Chike Mgbemena"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
You can maybe try this out: How do I customize the navigation drawer in Android Studios?
TL;DR: Create a ListView in your DrawerLayout with the appropriate implementation, Adapter, item.xml and such.
I found the way to display the original images, here is the fragment of code:
navigationView.setItemIconTintList(null);
"navigationView" is the name for my drawer, change it to yours on your MainActivity
I have long scroll form, and I need to scroll to its position on form is not valid input (for example, scroll to email edit text when it's not valid email or empty field)
I am facing 2 issues with scroll to EditText inside NestedScrollView
When one edit text is focused, all times scroll to take me directly to the focused scroll view, not to provided view coordinate
When there is no focused item, it's scrolling in a bad way, the wanted Edittext showing trimmed from the button
Note: I am using NestedScrollView with CoordinateLayout
Below is the layout
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/full_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f6f5">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="9dp"
android:layout_marginStart="9dp"
android:layout_marginTop="25dp"
android:text="#string/personal_details"
android:textColor="#a1143c"
android:textSize="14sp" />
<RelativeLayout
android:id="#+id/step1.rel.full_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/step.1.title.full_name"
style="#style/business_form_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/firstName" />
<EditText
android:id="#+id/step.1.feild.full_name"
style="#style/business_form_field"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/step.1.title.full_name"
android:inputType="textPersonName" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/step1.rel.last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/step.1.title.last_name"
style="#style/business_form_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_name" />
<EditText
android:id="#+id/step.1.feild.last_name"
style="#style/business_form_field"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/step.1.title.last_name"
android:inputType="textPersonName" />
</RelativeLayout>
<!--Rest Of Views-->
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
here is the style
<style name="business_form_field">
<item name="android:background">#drawable/roundedallsideswhite</item>
<item name="android:layout_marginStart">9dp</item>
<item name="android:layout_marginEnd">9dp</item>
<item name="android:textColor">#383838</item>
<item name="android:textSize">14sp</item>
<item name="android:gravity">start|center_vertical</item>
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="android:inputType">textAutoComplete</item>
<item name="android:paddingStart">15dp</item>
<item name="android:paddingEnd">15dp</item>
<item name="android:lines">1</item>
<item name="android:maxLines">1</item>
<item name="android:layout_marginTop">10dp</item>
</style>
I am a fresher to Android Design. I Have Android Studio's Navigational DrawerLayout, when my app loads I'm loading Initial Fragment for the app.
I want to make the toolbar transparent
I want to have an image that is overlapping the DrawerLayout's toolbar
and for other Fragments I want the same toolbar to be opaque.
First Screen when app Loads
When any other fragment is called
For No :1.
All you need to is to define theme which hide action bar, define action bar style with transparent background and set this style to the toolbar widget. Please note that toolbar should be drawen as last view (over all view tree)
<style name="Theme.Custom" parent="#android:style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="CustomActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar should be above content-->
<include layout="#layout/toolbar" />
</RelativeLayout>
Toolbar 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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/CustomActionBar"/>
For No : 2
Put ImageView in relative layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar should be above content-->
<include layout="#layout/toolbar" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:transitionName="photo_hero"
android:id="#+id/image"
/>
</RelativeLayout>
Toolbar 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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/CustomActionBar"/>
I am trying to make a alert dialog which will show like the picture.
Im trying to use frame layout but can't make the it right like the picture. In my current layout I used an imageView and textview.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#strings/text"
/>
</FrameLayout>
<!---<other layouts--->
</LinearLayout>
Create an Activity it represents your overlay.
Put this in your onCreate
requestWindowFeature(Window.FEATURE_NO_TITLE);
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); //importan no title show
super.onCreate(savedInstanceState);
setContentView(R.layout.overlay);
}
put this in styles.xml
<style name="FloatingPopup" parent="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
In your manifiest declare the activity thath looks like a overlay and add the theme
<activity
android:name=".YourOverlayActivity"
android:screenOrientation="portrait"
android:theme="#style/FloatingPopup" >
</activity>
It looks like a semitransparent activity and now you can custom with xml layout editor.
A FrameLayout will stack the Views, causing them to overlap each other. If you want one directly above the other, consider using a LinearLayout with the orientation set to vertical.
Update: Try this, replacing your FrameLayout with a LinearLayout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#strings/text"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
</LinearLayout>
Obviously fill in the src parameter for the ImageView with your image.