顯示具有 button 標籤的文章。 顯示所有文章
顯示具有 button 標籤的文章。 顯示所有文章

2015年11月3日 星期二

Menu Button

1.Add at the menu/main.xml


<menu 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"
    tools:context=".MainActivity">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_refresh"
        android:orderInCategory="10"
        android:title="@string/action_refresh"
        app:showAsAction="ifRoom" />
</menu>

2A  in Activity show the menu

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


2B in Fragment show the menu

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.forecastfragment,menu);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_refresh:

                break;
        }
        return super.onOptionsItemSelected(item);
    }



2015年10月29日 星期四

Change the button background

1.at drawable create a xml file.eg custom_button_background.xml

2.define the color in the values/colors.xml

3.in custom_button_background.xml


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

</selector>


android:state_pressed="true" define when press, the color change to this color.

4.Use


<Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="@drawable/custom_button_background"
        android:padding="5dp"
        android:text="@string/materiallize"
        android:textColor="@color/textColor" />


different state:

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList