implement the iOS round button in Android - android-layout

I am trying to create the iOS round button in Android. As you may know, Android buttons have grey background while the iOS round button has a clear background. I should use styles and themes to achieve this.
However, I do not know how to piece things together. Could anyone please give some advice?
Thanks

No need for styles or themes. The trick with buttons on Android is to use a separate image for each state, and then combine them all with a selector xml. You can put something like this in your drawable directory and reference it like an image:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_default_small_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_default_small_normal_disable" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_default_small_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_default_small_selected" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_default_small_normal" />
<item android:state_focused="true"
android:drawable="#drawable/btn_default_small_normal_disable_focused" />
<item
android:drawable="#drawable/btn_default_small_normal_disable" />
</selector>
Then just set the button background to this drawable. See State List for more information.

Related

how to remove white top and Botton border from Android option menu?

How can I remove that white top and Botton border from Android option men.
[1]: https://i.stack.imgur.com/5DJBX.jpg
<item
android:id="#+id/mail"
android:icon="#drawable/ic_launcher_background"
android:title="#string/menu"
android:visible="true" />
<item android:id="#+id/search_item"
android:title="Search" />
<item android:id="#+id/upload_item"
android:title="Upload" />
<item android:id="#+id/copy_item"
android:title="Copy" />
<item android:id="#+id/print_item"
android:title="Print" />
<item android:id="#+id/share_item"
android:title="Share" />
<item android:id="#+id/bookmark_item"
android:title="BookMark" />
[![enter image description here][1]][1]

Issues with theme after updating to the new android studio artic fox (2020.3.1)

Please understand that I started to use this program with almost no prior knowledge of java let alone designing an app.
So thing is that after updating to the version, it seems that the plugins(?) for the themes.xml dont work anymore. The error messages tell me that resouces are missing and honestly I dont know what this means or how to fix it.
Down below are the codes and a picture.
Thank you
<!-- Base application theme. -->
<style name="Theme.listest" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
The error message and the code
The problem is here:
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
You have not the color "colorPrimaryVariant"
you can add it or replace it with another one, for example:
<item name="android:statusBarColor" tools:targetApi="l">#color/purple_700</item>

Android - How to change the background color or the entire TabLayout dynamically?

I need to change the background color of my entire tab layout dynamically through code in my app. I just need to know the correct line to type. I don't need to change the selected tab or anything. I want to leave the style and text colors and the indicator line as is. I just want to change the background of the entire tab layout dynamically in code. Thank you for your help.
I have already tried the below line of code. Didn't work. Also included my TabLayout XML.
private TabLayout mTabLayout;
mTabLayout = (TabLayout) findViewById(R.id.tabs);
mTabLayout.setBackgroundColor
(this.getResources().getColor(R.color.dark_grey));
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
style="#style/CategoryTab"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_generic_margin_28"
app:tabBackground="#color/app_bar"/>
Thank you for your help.
I solved it by checking the boolean that I have set for night theme prior to setting the content view in onCreate.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences nightModeSwitchState = getSharedPreferences("NightModeSwitchState", 0);
mNightModeSwitchState = nightModeSwitchState.getBoolean("NightModeSwitchState", false);
if (mNightModeSwitchState) {
setContentView(R.layout.activity_book_night);
} else {
setContentView(R.layout.activity_book);
}
I have two layouts made both include tabLayouts. One of them references a style file for tabLayout set to night mode colors with the dark background and the layout references a style file set to regular colors for the tablayout.
<style name="CategoryTab" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="tabTextAppearance">#style/CategoryTabTextAppearance</item>
<item name="tabBackground">#drawable/tab_regular_theme</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="CategoryTabNight" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="tabTextAppearance">#style/CategoryTabTextAppearance</item>
<item name="tabBackground">#drawable/tab_layout_dark_mode</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
The style files reference different drawables that control the background colors as you can see above.. and here are the drawables...
Here is night mode drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/dark_grey" android:state_selected="true"/>
<item android:drawable="#color/dark_grey"/>
</selector>
Here is regular mode drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/app_bar" android:state_selected="true"/>
<item android:drawable="#color/app_bar"/>
</selector>
Everything else is the layouts are identical as not to mess anything up just the style files for the tablayouts are changed. I hope this makes sense. I tested it and it works for me. I have tried so many other things and nothing worked. It is important to call Shared Preference to get the value before checking the boolean. I hope this helps someone.

Nested Menu in Toolbar using Xamarin Forms

I would like to create Toolbar with sub menu items. It can be done in Xamarin.Android naively but I want to implement such a kind of feature in IOS and UWP too. I am not mentioning expandable list items. It should be similar to sub menu.
enter image description here
I have created this in Xamarin.Android using the below code
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:AMCSMobile="http://schemas.android.com/apk/res-auto">
<!-- Route View - Action Bar Menu -->
<item
android:id="#+id/RouteView_ActionButton_Messages"
android:icon="#drawable/ic_action_read_light"
AMCSMobile:showAsAction="always|withText"
android:title="#string/ScheduleView_ActionButton_Messages" />
<item
android:id="#+id/RouteView_ActionButton_Tracking"
android:icon="#drawable/ic_action_location_found_light"
AMCSMobile:showAsAction="ifRoom"
android:title="#string/RouteView_Button_TrackingOn" />
<item
android:id="#+id/RouteView_ActionButton_StartBreak"
android:icon="#drawable/ic_action_pause_light"
AMCSMobile:showAsAction="ifRoom"
android:title="#string/RouteView_Button_StartBreak" />
<item
android:id="#+id/RouteView_ActionButton_Complete"
android:icon="#drawable/ic_action_accept_light"
AMCSMobile:showAsAction="ifRoom"
android:title="#string/RouteView_Button_Complete" />
<item
android:id="#+id/RouteView_ActionButton_EventSelection"
android:icon="#drawable/ic_action_new_event_light"
AMCSMobile:showAsAction="always"
android:title="#string/ScheduleView_ActionButton_Event"
>
<menu>
<item
android:id="#+id/RouteView_ActionButton_Event_RecordRefuelEvent"
android:icon="#drawable/ic_action_refresh_light"
android:title="#string/ScheduleView_ActionButton_Event_RecordRefuelEvent" />
<item
android:id="#+id/RouteView_ActionButton_Event_RecordDisposalEvent"
android:icon="#drawable/ic_action_discard_light"
android:title="#string/ScheduleView_ActionButton_Event_RecordDisposalEvent" />
<item
android:id="#+id/RouteView_ActionButton_Event_RecordMiscEvent"
android:icon="#drawable/ic_action_help_light"
android:title="#string/ScheduleView_ActionButton_Event_RecordMiscEvent" />
<item
android:id="#+id/RouteView_ActionButton_Event_RecordBlockageEvent"
android:icon="#drawable/ic_action_warning_light"
android:title="#string/ScheduleView_ActionButton_Event_RecordBlockageEvent" />
</menu>
</item>
<item
android:id="#+id/RouteView_ActionButton_Commute"
android:icon="#drawable/ic_action_split_light"
AMCSMobile:showAsAction="never"
android:title="#string/RouteView_Button_ShowCommute" />
<item
android:id="#+id/RouteView_ActionButton_Logout"
android:icon="#drawable/ic_action_back_light"
AMCSMobile:showAsAction="never"
android:title="#string/RouteView_Button_Logout" />
</menu>
I want to know whether it is possible to do it in other platforms (IOS and UWP) or not. Kindly let me know your suggestion please.

Android Border Less Button Pressed State Background Color

How can we change the background colour of a Border less button when the button is pressed.
I used this:
android:background="?android:attr/selectableItemBackground"
android:text="#string/btn_skip"
Where my button Displays a label "SKIP" as defined in my "strings.xml".
Now When I test this it is Good Except It shows default "Blue" Colour when in Pressed State.
I want it to match it with other elements of my My UI theme that are "Orange" "#FF8800"
Any Ideas?
Thankx in advance...!
instead of using ?android:attr/selectableItemBackground you can create a xml in drawable in folder with following content.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/orange"/>
<item
android:state_enabled="false"
android:drawable="#color/default"/>
<item
android:drawable="#color/default"/>
</selector>
Updated:
so you save this files as : btn_drawable.xml in drawable folder.
Simply replace ?android:attr/selectableItemBackground
with *#drawable/btn_drawable.xml*
Thanks #Nimish-Choudhary ...! I followed your advice. and I have explained it further for clarity to all having same question as me as a beginner.
Create an xml with name say "btntransparent.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/pressed"/>
<item
android:state_enabled="false"
android:drawable="#color/defaultColor"/>
<item
android:drawable="#color/defaultColor"/>
</selector>
Next add the colors "pressed" and "defaultColor" to another xml say "colors.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed">#CCFF8800</color>
<color name="defaultColor">#00000000</color>
</resources>
Here "#CCFF8800" is my pressed state Translucent Orange and "#00000000" is the 100% Transparent Black (;-) thats invisible). You can find more about color codes at Color| Android Developers
Now put the "colors.xml" in values Folder and "btntransparent.xml" in drawable Folder.
Now the last step is to voila use it in the button as
<Button
android:id="#+id/id_btn_skip"
android:background="#drawable/transparentbtn"
android:onClick="skipToMain"
android:text="#string/btn_skip" />
And thats should do the job...!
Take care.
regards,
raisedadead
If I understand you correctly, what you could do is add new resource in #drawable for example my_ripple.xml
<?xml version="0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF8800">
</ripple>
Then simply set this as your background.
In your theme add the following:
<item name="android:selectableItemBackground">#FF8800</item>
to override the default blue.

Resources