I'm trying to create a custom navView in my app but I get this weirdest bug.
I can't get the "menu" button to look like the others.
It's not pressed in the image, it just like that all the time.
this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".activities.BottomNavView">
<FrameLayout
android:id="#+id/flFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="75dp"
android:theme="#style/NavTheme"
android:background="#drawable/toolbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0."
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav_bar"
app:itemIconSize="30dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is my theme:
<style name="NavTheme" parent="Theme.MaterialComponents.BottomSheetDialog">
<item name="colorPrimary">#color/colorBlack</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/colorBlue</item>
<item name="colorNavigationItemSelected">#color/colorGray</item>
</style>
itried Theme.MaterialComponents.Light.DarkActionBar as well.
this is my menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/list"
android:title="#string/menu"
android:enabled="true"
android:icon="#drawable/menu" />
<item
android:id="#+id/search"
android:title="#string/search"
android:enabled="true"
android:icon="#drawable/search"/>
<item
android:id="#+id/home"
android:title="#string/map"
android:enabled="true"
android:icon="#drawable/home"/>
<item
android:id="#+id/liked"
android:title="#string/heart"
android:enabled="true"
android:icon="#drawable/liked"/>
<item
android:id="#+id/add"
android:title="#string/plus"
android:enabled="true"
android:icon="#drawable/add"/>
</menu>
the image is
I can't understand why it's have the text beneath and this different look.
use labelVisibilityMode to unlabeled to remove the text under the menu item
app:labelVisibilityMode="unlabeled"
Related
I'm trying to achieve something like this in Android Studio:
I don't want the background shape to be as the TextView size, I want it half the size just like the above image. This is what I tried to do:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="30dp">
<shape android:shape="rectangle" >
<solid android:color="#f3f3f3" />
</shape>
</item>
<item android:top="20dp">
<shape android:shape="rectangle" >
<solid android:color="#FFC107" />
</shape>
</item>
</layer-list>
and it looks like this:
not exactly what I wanted. how can I do it like in the image above?
Try this:
define in a res/drawable new file called double_color.xml :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/shape_rectangle">
<shape android:shape="rectangle" >
<solid android:color="#color/green" />
</shape>
</item>
<item android:top="-10dp" android:right="-10dp" android:left="-10dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="10dp"
android:color="#android:color/white"/>
</shape>
</item>
</layer-list>
Than define a new style in res/values as:
<style name="TexViewStyle" parent="TextAppearance.AppCompat">
<item name="android:background">#drawable/double_color</item>
</style>
And last add style to your textView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Full name"
style="#style/TexViewStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Will be like this:
I wanna remove the shadow or the line after the name of app
When i put that code
0dp
in XML i get the following error: invalid parent reference 'style/Widget.AppCompat.Light.ActionBar.Solid.Inverse'.
You need to use toolbar widget to set the elevation same as your TabLayout, try to add toolbar above your TabLayout (im using LinearLayout) like this :
<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="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:elevation="4dp"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/darker_gray"
app:tabIndicatorColor="#android:color/white"
app:tabIndicatorHeight="2dp"
android:elevation="4dp">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RELIGIOUS" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ANCIENT" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MUSEUMS" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EVENTS" />
</android.support.design.widget.TabLayout>
also, you need new style to remove default toolbar, let say we have this new style
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
// this 2 code to remove toolbar and we can use custom toolbar
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
then use this style to your activity, example :
<activity android:name=".MainActivity"
android:theme="#style/AppThemeNoActionBar"> // this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
last, define our new toolbar in activity.
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string.app_name);
Hope it helps :)
Navigation Drawer header cuttoff by action bar.But I need navigation drawer over action bar.My Navigation drawer show in image
My style .xml
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="actionBarTheme">#style/AppTheme.AppBarOverlay</item>
<item name="actionBarPopupTheme">#style/AppTheme.PopupOverlay</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/sapphire_blue_light</item>
<item name="background">#color/sapphire_blue_light</item>
</style>
And Drawer layout i add this line alsio
android:fitsSystemWindows="true"
But i need result like below image.
Result image i need this
My drawer layout.
My customized navigation drawer.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
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.support.design.widget.FloatingActionButton
android:id="#+id/fab_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/left_drawer_layout"
android:layout_height="match_parent"
android:layout_width="260dp"
android:layout_gravity="start"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#color/grey"
android:orientation="vertical"
>
<include layout="#layout/nav_header" />
<ListView
android:id="#+id/left_drawer_child"
android:layout_width="260dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#color/listview_side_view"
android:dividerHeight="0dp"
android:background="#color/listview_side_view"/>
</LinearLayout>
</android.support.design.widget.NavigationView>
I think your problem is with theme MyActionBar :-
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/sapphire_blue_light</item>
<item name="background">#color/sapphire_blue_light</item>
</style>
Try after removing:-
<item name="background">#color/sapphire_blue_light</item>
If this not work try removing:-
<item name="android:background">#color/sapphire_blue_light</item>
I'm not sure why when I run my emulator, everything in my Layout XML doesn't appear but the emulator only shows everything that is in my Menu Xml.
Hope someone can help. Thank you
(Using Android Studio)
The layout xml is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.zainuddeen.myapplication.Main2Activity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
and menu xml is:
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_search_black_48dp"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item
android:id="#+id/action_favorite"
android:icon="#drawable/ic_favorite_black_24dp"
android:title="#string/action_favorite"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="#+id/action_share"
android:title="#string/action_share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
I think you design different xml and run different
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
put the name of layout in R.layout.mylayout
I have a situation similar to this one, however, the method supposed there isn't working for me. I've tried different variation with tag but nothing has helped so far.
Here's my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="#string/hello" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="20"
android:progress="0"
android:secondaryProgress="0"
android:progressDrawable="#drawable/seekbar_progress" />
</LinearLayout>
drawable-mdpi/seekbar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/passive_progress">
<shape>
<corners android:radius="0dp" />
</shape>
</item>
<item
android:id="#android:id/progress"
android:drawable="#drawable/active_progress">
<clip>
<shape>
<corners android:radius="0dp" />
</shape>
</clip>
</item>
</layer-list>
Thank you.