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 :)
Related
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"
If i put the button before appbar it does not show up. If i put it inside, it shows up but it does not fit properly (height is under imageview and the two can not be in the same height). I tried different layouts other than coordinatorlayout and it hapens again there too.
<?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:alpha="1"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/search_button"
android:layout_width="55.5dp"
android:layout_height="55.5dp"
android:layout_marginLeft="298.5dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_baseline_search_24" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<ImageView
android:id="#+id/title"
android:layout_width="155dp"
android:layout_height="55.5dp"
android:minHeight="?actionBarSize"
android:src="#mipmap/ic_banner_foreground" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabGravity="center"
app:tabMode="auto" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="59dp"
android:layout_marginTop="672dp"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme.AppBarOverlay">
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="566dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="566dp" />
</androidx.viewpager.widget.ViewPager>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
It is not showing because you've used "#android:color/transparent" as background for your ImageButton. Chose another color and it will be visible. Or just add some text so that you can see it.
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
Running Android Studio 1.0.2 and am having problems resizing a spinner.
I would like the layout to be 50/50 on a single line.
text : spinner.
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="country_arrays">
<item>Malaysia</item>
<item>United States</item>
<item>Indonesia</item>
<item>France</item>
<item>Italy</item>
<item>Singapore</item>
<item>New Zealand</item>
<item>India</item>
</string-array>
</resources>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TableLayout
android:id="#+id/tblSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="100">
<TableRow>
<TextView
android:id="#+id/textViewSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="Select item:"/>
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:entries="#array/country_arrays"/>
</TableRow>
</TableLayout>
</RelativeLayout>
Currently the spinner is taking up about 90% of the width with the textview 10%.
Try to change android:layout_width to fill_parent
Try changing your layout width from wrap_content to an actual width. It will be specific your layout and platform so use with care.
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33777777"
android:layout_margin="1dip"
android:gravity="center_vertical"
android:padding="5dip">
<TextView
android:id="#+id/profileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView\nthis" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
a`ndroid:layout_width="30dip"`
android:layout_height="wrap_content" />
</TableRow>