I have a layout for bottom tabs. However, I am not able to set the strip on top of tabHost. How to do it? Thank you.
here my main layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>
and also a selector for tab style:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#aa3434"
android:endColor="#432233"
android:angle="270"
/>
</shape>
</item>
<item android:state_selected="true" >
<shape>
<gradient
android:startColor="#aa3434"
android:endColor="#432233"
android:angle="270" />
</shape>
</item>
Try this code
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
</LinearLayout>
</TabHost>
Related
I'm breaking my head wis an error.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".ScanningChoice">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/app_bar"
style="#style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/background_color"
app:navigationIcon="#drawable/ic_baseline_add_box_24"
app:title="Scanare"
app:titleTextColor="#FFFFFF"
app:menu="#menu/scan_specific_item"
/>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/butonScanare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="64dp"
android:contentDescription="#string/scanare"
app:srcCompat="#drawable/ic_baseline_add_a_photo_24" />
<ListView
android:id="#+id/table_main"
android:layout_marginTop="56dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/search"
android:icon="#drawable/ic_baseline_search_24"
android:title="#string/search"
android:contentDescription="#string/details_about_object"
app:showAsAction="always" />
</menu>
The issue seems to be with the app:menu="#menu/scan_specific_item"
When I remove it it looks like this:
but it lacks the search icon I desire to use.
I've been stuck with this problem for about 5 hours.
Any clue what's wrong?
I want to put this little green line in the menu item that is active ... already has to create a shape and a custom style but no success ...
My activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_ordem"
android:checked="true"
android:title="Home"/>
<item
android:id="#+id/nav_auto_infracao"
android:title="Payment Profile" />
<item
android:id="#+id/nav_apreensao_deposito"
android:title="Payment history" />
<item
android:id="#+id/nav_doacao"
android:title="My card" />
<item
android:id="#+id/nav_sincronia"
android:title="Frinds" />
</group>
</menu>
Try to use View to draw line.
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
One way to solve this is you can highlight the item by calling the following method to detect when to change the visibility and position the view:
onNavigationItemSelected(navigationView.getMenu().getItem(0));
Since you've mentioned you already have a shape and a custom style, put the view (here in this code below, selectedItemBottomView) inside the NavigationView in activity_main or the XML layout file where you've used the activity_main_drawer like this:
activity_main
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/activity_main_drawer" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/selectedItemBottomView"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#color/green" />
</LinearLayout>
</RelativeLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
On selected, change the visibility or position as per your requirement:
selectedItemBottomView.setVisibility(View.VISIBLE);
Hope this helps.
I have a Navigation Drawer that contains several items.
I added a button on the bottom of the Navigation Drawer.
The problem is that in small size screens the button covers the last item in the Drawer.
How can I add some space under the last item so the button won't cover anything?
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" >
<Button
android:id="#+id/remove_ads_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/red"
android:text="#string/remove_ads"
android:textColor="#color/white"
android:textSize="15sp" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
activity_main_drawer.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="none">
<item
android:id="#+id/action_contact_us"
android:icon="#drawable/ic_contact_us"
android:title="#string/action_contact_us" />
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_share_24dp"
android:title="#string/action_share" />
<item
android:id="#+id/action_rate_us"
android:icon="#drawable/ic_rate_us_24dp"
android:title="#string/action_rate_us" />
<item
android:id="#+id/action_follow_us"
android:icon="#drawable/ic_follow_us_24dp"
android:title="#string/action_follow_us" />
<item
android:id="#+id/action_help"
android:icon="#drawable/ic_help_name"
android:title="#string/action_help" />
<item
android:id="#+id/action_about_us"
android:icon="#drawable/ic_info_24dp"
android:title="#string/action_about_us" />
<item
android:id="#+id/action_settings"
android:icon="#drawable/ic_settings_24dp"
android:title="#string/action_settings" />
</group>
</menu>
I came up with an idea how to do it and it worked for me.
What I needed to do is to add one more Item to the Drawer and then disable it.
The code is:
<item
android:title=""
android:enabled="false" >
</item>
Very simple and easy!!!
May be you can try something like this
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/remove_ads_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/red"
android:text="#string/remove_ads"
android:textColor="#color/white"
android:textSize="15sp" />
<ScrollView
android:id="#+id/my_scroll_view"
android:layout_above="#id/remove_ads_button"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/padding_10dp">
<include layout="#layout/nav_header_main"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/action_contact_us"
android:textSize="#dimen/text_30sp"
android:drawableRight="#drawable/ic_contact_us"
android:drawablePadding="8dp"/>
<!--another menu items-->
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
This is what I currently have
This is what I want to achieve
Here is the xml layout
<LinearLayout
android:layout_width="wrap_content"
android:id="#+id/contentLayout"
android:orientation="vertical"
android:gravity="top|center"
android:background="#drawable/background_containernav"
android:layout_height="wrap_content"
android:padding="4dip" >
<Spinner
android:id="#+id/spnShapes"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<CheckBox
android:text="Fill"
android:id="#+id/chkFill"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnPickColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Color" />
</LinearLayout>
<ImageView
android:clickable="true"
android:id="#+id/slideHandleButton"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/ic_buttonnav"
android:layout_height="fill_parent"
android:background="#drawable/background_buttonnav"/>
</SlidingDrawer>
Here is the background_containernav.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#878787"/>
</shape>
</item>
<item android:left="4px">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#fefefe"/>
</shape>
</item>
</layer-list>
What should I do to achieve to the latter? Thank you very much.
I'm having an issue with a ListView and a ScrollView and adding a drop shadow between the listview and the ScrollView.
I had made a shape, which works great with a ListView and a relative layout, but does not work with the ScrollView.
I have done the following - Dashboard List
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:choiceMode = "singleChoice"
android:listSelector="#31ABD4"
android:drawSelectorOnTop="false"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data"/>
</RelativeLayout>
Dashboard with scroll view
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<View
android:layout_width="10dp"
android:layout_height="fill_parent"
android:background="#drawable/shadow_left" />
</RelativeLayout>
</ScrollView>
View
<?xml version ="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="180"
android:width="10dp"
android:centerX="0.1"
android:gravity="right"
android:startColor="#00000000"
android:endColor="#55000000"
android:type = "linear"
/>
</shape>
Edit - Attached Screenshots
Thank you all,
James
seems that you are missing the paddings on "Dashboard with scroll view"
try this instead
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<View
android:layout_width="10dp"
android:layout_height="fill_parent"
android:background="#drawable/shadow_left" />
</RelativeLayout>
</ScrollView>