+2 votes
by (100 points)

I'm trying to allow the user to set his own color themes. I've managed to accomplish this with

attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="extra_light" format="reference" />
</resources>

styles.xml

<style name="Green" parent="@style/AppTheme">
    <item name="extra_light">@color/extra_light_green</item>
</style>

colors.xml

<resources>
    <color name="extra_light_green">#C5E26D</color>
</resources>

This works well for most of the application however I have a selector which previously had

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/extra_light_green" />
</selector>

to

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="?attr/extra_light" />
</selector>

Now it crashes.

Here's the logcat, any ideas on how to solve this?

 FATAL EXCEPTION: main
 android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
 at android.view.LayoutInflater.createView(LayoutInflater.java:683)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at com.android.internal.policy.impl.MiuiPhoneLayoutInflater.onCreateView(MiuiPhoneLayoutInflater.java:44)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:730)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816)
at android.view.LayoutInflater.inflate(LayoutInflater.java:559)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:419)

EDIT

Here is where I apply the selector

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginLeft="10dp"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/row_menu_title"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/selector_item_news"
        android:gravity="center_vertical"
        android:padding="10dp"
        android:text="Medium Text"
        android:textSize="16sp" />

</LinearLayout>

10 Answers

+17 votes
by (100 points)

Attrubutes supported from API 23 Item attributes , on later versions ColorStateList can be created programatically with AppCompatResources and used with required view.

selector menu_item_text_color.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="?attr/menu_item_text_color_selected" android:state_checked="true" />
    <item android:color="?attr/menu_item_text_color" /> <!-- Default -->
</selector>

in source code

navigationView.setItemTextColor(AppCompatResources.getColorStateList(this, R.color.menu_item_text_color));
+17 votes
by (100 points)

I have found a workaround for this issue. It seems that android can't apply color when the drawable is expected.

Create a solid shape drawable named item_news_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="?attr/extra_light"/>
</shape>

And then modify your "selector_item_news.xml"

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/item_news_drawable" />
</selector>

I used color for background not for pressed state. But after this code applied, background of textview is changed regarding application theme.

UPD : I have tested my solution on Android L preview. But on Android 4.4.2 it also crashes with Resources$NotFoundException. Details in this answer

+15 votes
by (100 points)

Z-indices are local inside their clipping hierarchical parent context. This is very non-intuitive. They have their own z-stack context, which normally parallels that of the enclosure hierarchy. But they're still subject to clipping! Which can be a real pain if you're intuitively expecting the z-indices to be absolute .

Note that some jquery containers, such as accordion, quietly specify overflow: auto. Even if it's not explicitly in your code. (This can be overridden locally after it's found.)

Also note that if overflow-x: visible is set, but overflow-y is set to a non-visible, then the rendering engine quietly internally changes overflow-x to be the same as overflow-y for your amusement. But you found this out already.

You probably should be able to circumvent the unwanted non-"visible" overflow clipping, even with your high z-index, by invoking transform: translate(0,0); [or whatever desired offset, % or pixels] inside the style of the div that you want to levitate. Transform should create a new local z-stack for that element and its children. Which will let you get around an overly-restrictive parent or grandparent.

+12 votes
by (100 points)

Choose some different systemctl call, which differs for existing and non-existing services. For example

systemctl cat sshd

will return exit code 0 if the service exists and 1 if not. And it should be quite easy to check, isn't it?

+9 votes
by (100 points)

You can set weightSUm on LinearLayout and it can be a value, like 1, and then those 2 views(TextView and ImageView) half of that sum, because are 2 views(1 div 2)

Code should look like this.

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5" />
</LinearLayout>

Don't forget to set width and height for both views to match parent.

+8 votes
by (100 points)
 $str = 'In My Cart : 11 12 items';
 preg_match_all('!\d+!', $str, $matches);
 print_r($matches);
+4 votes
by (100 points)

To fix your current code, you should return the value.

def get_input():
    choice = input("[R]ock, [P]aper, or [S]cissors? ").lower()
    if choice == 'r':
        return 'rock'
    elif choice == 'p':
        return 'paper'
    elif choice == 's':
        return 'scissors'
    else:
        print("That is not a valid command. Try again.")
        return get_input()
#       ^^^^^^

choice = get_input()
print(choice)

However, if the user provides too many incorrect inputs, the stack will end up growing too large. What you want is a loop:

def get_input():
    while True:
        choice = input("[R]ock, [P]aper, or [S]cissors? ").lower()
        if choice == 'r':
            return 'rock'
        elif choice == 'p':
            return 'paper'
        elif choice == 's':
            return 'scissors'
        # go through the loop again.

choice = get_input()
print(choice)
0 votes
by (100 points)

If you do not care about the case you can just change

char[] dizimiz = str.toCharArray();

to

char[] dizimiz = str.toLowerCase().toCharArray();

That will accomplish your question

How can i sort char[] array case insensitive?

If there is something else I am missing here please let me know and I will update my answer.

As per the comments below I have made a rough code for you to sort and retain the output with the proper casing.

    char[] dizimiz = str.toCharArray();
    char[] lc = str.toLowerCase().toCharArray();
    char temp;
    Boolean done;
    if (lc.length > 1) do {
        done = true;
        for (int i = lc.length - 1; i > 0; i--) {
        if (lc[i] < lc[i - 1]) {
            temp = lc[i - 1];
            lc[i - 1] = lc[i];
            lc[i] = temp;
            temp = dizimiz[i - 1];
            dizimiz[i - 1] = dizimiz[i];
            dizimiz[i] = temp;
            done = false;
           }
        }
    } while (!done);
0 votes
by (100 points)

You are probably using join() in Java7. Join doesn't work. It requires a context switch and Java programs can't do a context switch so the framework creates "continuation threads" to keep moving. I detailed that problem several years ago in this article: ForkJoin Clamamity

0 votes
by (100 points)

Try getAttribute() with any of the below values: "value", "innerText", "innerHTML"

Related questions

+7 votes
11 answers
+15 votes
9 answers
+2 votes
8 answers
+14 votes
10 answers
...