ad728

Monday, July 18, 2016

AIDE Tutorial - 18 Night mode(Checkable Menu Item)


XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:id="@+id/lll">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
Java
package com.kc.nightmode;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.*;


public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

@Override
public boolean onCreateOptionsMenu(Menu mmm)
{
// TODO: Implement this method
mmm.add("Night Mode").setCheckable(true);
return true;


}

@Override
public boolean onOptionsItemSelected(MenuItem iii)
{
LinearLayout lll=(LinearLayout) findViewById(R.id.lll);
// TODO: Implement this method
if(iii.isChecked()){
iii.setChecked(false);
lll.setBackgroundColor(Color.parseColor("#ffffff"));
}else{
iii.setChecked(true);
lll.setBackgroundColor(Color.parseColor("#333333"));
}
return true;
}

}
Watch video and try it
Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300

Blog Archive