The material design is missing, and with it some of the new magical features that were difficult to use with the usual skills that are supposedly found only in Silicon Valley. Pun intended.
Anyway, I'm trying to get the Ripple effect working on API <21, that is, with pre-installed devices. In the most literal sense, the ripple effect, water, for that matter.
Here is what I have tried. This approach is simple. I draw three layouts in gray, three white, then three other white and three gray, and then shut up.
However, the implementation did not work. Only minor runs and effects are not realized.
Here is my .java activity:
package dreamnyc.ripple;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class MainActivity extends ActionBarActivity {
public String TAG = "okay";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button b;
final RelativeLayout la1;
final LinearLayout la2, la3, la4, la5, la6, la7;
la1 = (RelativeLayout) findViewById(R.id.l1);
la2 = (LinearLayout) findViewById(R.id.l2);
la3 = (LinearLayout) findViewById(R.id.l3);
la4 = (LinearLayout) findViewById(R.id.l4);
la5 = (LinearLayout) findViewById(R.id.l5);
la6 = (LinearLayout) findViewById(R.id.l6);
la7 = (LinearLayout) findViewById(R.id.l7);
b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
la7.setBackgroundColor(Color.LTGRAY);
final Runnable r1 = new Runnable() {
@Override
public void run() {
synchronized (this) {
try {
la7.setBackgroundColor(Color.WHITE);
la6.setBackgroundColor(Color.LTGRAY);
la4.setBackgroundColor(Color.LTGRAY);
la2.setBackgroundColor(Color.LTGRAY);
la5.setBackgroundColor(Color.WHITE);
la3.setBackgroundColor(Color.WHITE);
la1.setBackgroundColor(Color.WHITE);
wait(100);
} catch (InterruptedException e) {
Log.d(TAG, "exception encountered" + e);
}
synchronized (this) {
try {
final Runnable r2 = new Runnable() {
@Override
public void run() {
la7.setBackgroundColor(Color.WHITE);
la5.setBackgroundColor(Color.LTGRAY);
la3.setBackgroundColor(Color.LTGRAY);
la1.setBackgroundColor(Color.LTGRAY);
la6.setBackgroundColor(Color.WHITE);
la4.setBackgroundColor(Color.WHITE);
la2.setBackgroundColor(Color.WHITE);
}
};
wait(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
};
runOnUiThread(r1);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/l1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:padding="15dp"
android:id="@+id/l2">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:id="@+id/l3">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:id="@+id/l4">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:id="@+id/l5">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:id="@+id/l6">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="15dp"
android:id="@+id/l7">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Ripple"
android:id="@+id/button"
android:layout_marginTop="130dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
, IDE, , , , runnable.
:
Runnable one alone:
Runnable two alone:
: , , .
user2320244