Definite bug in Android Studio regarding Spinners and the `clickable` attribute? - android-studio

In my app, I want to make my spinners clickable=true or clickable=false at different times. But, despite setting the attribute both in the Attributes Inspector and in code, Android Studio simply does not respect the clickable attribute.
(I do NOT want to enable/disable the spinners, because that changes the way they are displayed, ie. greyed out.)
Here's a bare-bones project to show....
activity_main.xml
<?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=".MainActivity">
<Spinner
android:id="#+id/spinnerA"
android:layout_width="0dp"
android:layout_height="50dp"
android:clickable="false"
android:entries="#android:array/organizationTypes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/spinnerB"
android:layout_width="0dp"
android:layout_height="50dp"
android:entries="#android:array/imProtocols"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinnerA" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.heewhack.clickablespinners
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
spinnerB.isClickable = false
}
}
This seems to be a major bug in Android Studio...
Questions:
Can someone confirm my findings, or better yet, show me what I'm missing?
Does anyone know a work-around?
Can I change the way enabled/disabled items are displayed?
How should I report this bug, if it's actually a bug?

Related

Why Relativelayout doesn't work on fragments?

I have created a bottom navigation bar from this tutorial https://www.youtube.com/watch?v=JS3DIb4x1JQ&t=1352s, but RelativeLayout doesn't work properly on fragments.
Here is the code of bluetooth fragment with textview in the middle:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<TextView
android:id="#+id/bluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0472FE"
android:text="Bluetooth"
android:textSize="30dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
This is what it looks like in
design
And this is what it looks like in
android emulator
How do I fix it?
Are there other components in this view? check the main view if it set to match_parent.

keyboard hides actionbar while using adjustPan

I have a chat which is "mixed", the editText and send button is in java / native and my chat system is in a server and I load it inside of a webview.
I would like to adjust my webview with my keyboard when the user starts typing. I used adjustPan for that and works, but now my actionbar somehow is hidden when the keyboard is open.
Here is part of my android manifest for my Activity:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
</activity>
Here is my chat.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="#+id/llFooter">
</WebView>
<LinearLayout
android:id="#id/llFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/chat_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:maxLines="3"
android:hint="Schreibe deine Nachricht hier..">
</EditText>
<Button
android:id="#+id/chat_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:text=">">
</Button>
</LinearLayout>
</RelativeLayout>
Note: my chat is a fragment
Anyone has an idea how can I fix it?
I already checked these links without success:
ActionBar is hiding when keyboard appears
Soft Keyboard Hiding ActionBar while using adjustPan
EDIT 1: SCREENSHOTS ADDED
AdjustPan: The actionbar is hidden but the chat webview fits with the keyboard
AdjustResize: The actionbar is not hidden but the chat webview doesnt fit. Should scroll down until the last messages

Update Actionbar smoothly - Xamarin Android

i am trying to customize my Actionbar and so far i got what i wanted (i need to format it so that it looks nice, but i have the raw design that i wanted).
Now my Actionbar looks like this:
But now i am having the problem that my Actionbar looks like this when my app is being started:
and after 1-2 few seconds it "jumps" to the design above(when the Activity is fully started).
So my question is if it is possible that at least the right bachground of the Actionbar is being loaded ad start and that the icons appear when the activity is fully loaded (or even if it is possible to load the complete new Actionbar at start)
This is the way i am customizing the Actionbar:
protected override void OnCreate(Bundle bundle)
{
RequestWindowFeature(WindowFeatures.ActionBar);
base.OnCreate(bundle);
// this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
// Set our view from the "main" layout resource
ActionBar mActionBar = this.ActionBar;
mActionBar.SetDisplayShowHomeEnabled(false);
mActionBar.SetDisplayShowTitleEnabled(false);
mActionBar.SetCustomView(Resource.Layout.custom_actionbar);
mActionBar.SetDisplayShowCustomEnabled(true);
SetContentView(Resource.Layout.Main);
}
And here is the layout for my new Actionbar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#E1E2E3">
<TextView
android:id="#+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold"
android:text="olla" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:src="#drawable/back_ico" />
<Button
android:id="#+id/ususal1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="8dp"
android:background="#drawable/butt_toolbar_style"
style="#style/button_text"
android:text="abc" />
<Button
android:id="#+id/ususal2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="8dp"
android:background="#drawable/butt_toolbar_style"
style="#style/button_text"
android:text="def"
android:visibility="invisible" />
</RelativeLayout>
I have also seen that there is such thing as an ActionBar.IOnMenuVisibilityListener which should be called before the Actionbar is being shown, but it somehow never gets executed (or maybe i am dosing something wrong)
Kind Regards
Did you find solution for this?
I had the same problem and had to put a theme to the application element in the AndroidManifest.xml file.
styles.xml
<style name="home">
<item name="android:layout_height" >wrap_content</item>
<item name="android:layout_width" >fill_parent</item>
</style>
AndroidManifest.xml
<application android:label="myappname" android:theme="#style/home">
this is what you have to add to make it work.
Leave the rest of the code as is.

In Android, how do I position an image on top of another to look like a badge?

Please see below:
I tried using Absolute layout, but that's deprecated. I appreciate your help, thanks.
RelativeLayout is a great option.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:scaleType="centerCrop"
android:src="#drawable/iconImage" />
<ImageView
android:id="#+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/icon"
android:layout_alignTop="#+id/icon"
android:src="#drawable/badge" />
If you actually want a badge with a dynamic number/text, then you can make the second ImageView a TextView (or a ViewGroup such as LinearLayout or RelativeLayout) and give it a background drawable and set the text to what you want.
Have a look at the ViewBadger project on github(but keep in mind that you shouldn't try to copy other platforms UI elements in android apps).

Android: How to build tabs like the ones show on Android UI Page

So android goes out of its way to build this nice UI guide for everyone to use. But I don't see anywhere where it shows code examples of how to build these elements.
The UI guidelines for tabs can be found here. http://developer.android.com/design/building-blocks/tabs.html.
Does anyone know how to create tabs likes the this one?
Any help would be appreciated, thanks.
SOLUTION POSTED
Ok, so here is what I ended up doing after probably wasting about 10 hours trying to make some good looking tabs.
First I scrapped the whole idea of using android's implementation of tabs. For one reason the tab host widget is suppose to deprecated for the action bar, but the action bar only works from android 3 on.
I finally figured out that if a used a linear layout and as the background for the linear layout i put the image I wanted to use (using a 9 patch image). Then create another linearlayout and textview in order to put text over top of that linearlayout. Then make your linear layout clickable. Then as you get more advanced you can make you linear layout background a xml selector and you are good to go. Incase you didn't get all that here is my code.
LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#color/main_screen_bg_color"
android:orientation="horizontal"
android:padding="2dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/selector_not_current"
android:clickable="true"
android:onClick="onClickSub"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Example 1"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/selector_current"
android:clickable="true"
android:onClick="onClickFoodDetails"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Example 2"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Example Selector
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/selected_pressed_tab" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="#drawable/selected_pressed_tab" /> <!-- focused -->
<item android:drawable="#drawable/selected_tab" /> <!-- default -->
Hope this helps everyone. Android tabs were just too difficult an annoying to work with that it was easier just to make my own from scratch. Good Luck!
do something like this.
this is a full working code. enjoy
somewhere in oncreate method of activity extending Tabactivity
tabHost = getTabHost();
Intent intent;
intent = new Intent().setClass(this, FirstActvity.class);
setupTab("NearBy", intent, R.drawable.firsttabdrawable);
intent = new Intent().setClass(this, SecondActivity.class);
setupTab("History", intent, R.drawable.secondtabdrawable);
intent = new Intent().setClass(this, ThirdActivity.class);
setupTab("Setting", intent, R.drawable.thirdtabdrawable);
define setupTab methods as
private void setupTab(String tag, Intent intent, int selectorId) {
View tabView = LayoutInflater.from(tabHost.getContext()).inflate(R.layout.view, null);
tabView.setBackgroundResource(selectorId);
TabSpec setContent = tabHost.newTabSpec(tag).setIndicator(tabView).setContent(intent);
tabHost.addTab(setContent);
}
view.xml as
<?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"
>
</LinearLayout>
and firsttabdrawable.xml in drawable folder as
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="#drawable/selectedfirsttabimage"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="#drawable/notselectedfirsttabimage" />
</selector>
define secondtabdrawable.xml and thirddrawable.xml in the same way
The tabs you need are part of the ActionBar. Specifically they are displayed when the ActionBar is in Navigation Tab mode.
http://developer.android.com/guide/topics/ui/actionbar.html
(see under "Adding Navigation Tabs")
You may want to use www.ActionbarSherlock.com which is a library that will give you the ActionBar on nearly all versions of Android. It works the same as the official one, and includes the tabs.
Do not use the TabActivity any more, it's old and being deprecated. ActionBar is the future.

Resources