在Android

时间:2016-03-27 18:40:42

标签: java android

晚上好,我还是一个带代码的菜鸟,我想知道是否有人可以提供帮助:)

我想在我已经制作的活动上放置一个操作栏,我还想添加应用程序图标,但我已经知道该怎么做了,我只是想知道怎么做动作杆

package app.alexdickson.com.workout1;

import android.app.AlarmManager;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;


public class Main2Activity extends AppCompatActivity implements  View.OnClickListener{
ImageButton botoFlexio;
ImageButton botoAbdominals;
static final int DIALOG_ID = 0;
int hour_x;
int minute_x;
int hourDefinitivaFlexio;
int minuteDefinitvaFlexio;
int hourDefinitivaAbs;
int minuteDefinitivaAbs;
PendingIntent pending_intent1;
PendingIntent pending_intent2;
Context context;
AlarmManager alarm_manager1;
AlarmManager alarm_manager2;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    this.context = this;
    botoFlexio = (ImageButton) findViewById(R.id.botoFlexio);
    botoAbdominals =  (ImageButton) findViewById(R.id.botoAbdominals);
    botoFlexio.setOnClickListener(this);
    botoAbdominals.setOnClickListener(this);
    alarm_manager1 = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarm_manager2 = (AlarmManager) getSystemService(ALARM_SERVICE);





}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.botoFlexio:
            botoFlexio.setBackgroundResource(R.drawable.flexioclicat);
            showDialog(DIALOG_ID);
            hourDefinitivaFlexio = hour_x;
            minuteDefinitvaFlexio = minute_x;
            final Calendar calendar1 = Calendar.getInstance();
            calendar1.set(Calendar.HOUR_OF_DAY,hourDefinitivaFlexio);
            calendar1.set(Calendar.MINUTE, minuteDefinitvaFlexio);
            final Intent my_intent1 = new Intent(this.context, Alarm_Receiver1.class);
            pending_intent1 = PendingIntent.getBroadcast(Main2Activity.this,0,
                    my_intent1, PendingIntent.FLAG_UPDATE_CURRENT);
            //Alarm manager
            alarm_manager1.set(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(),
                    pending_intent1);

            break;

        case R.id.botoAbdominals:
            botoAbdominals.setBackgroundResource(R.drawable.abdominalsclicat);
            showDialog(DIALOG_ID);
            hourDefinitivaAbs = hour_x;
            minuteDefinitivaAbs = minute_x;
            final Calendar calendar2 = Calendar.getInstance();
            calendar2.set(Calendar.HOUR_OF_DAY,hourDefinitivaAbs);
            calendar2.set(Calendar.MINUTE, minuteDefinitivaAbs);
            final Intent my_intent2 = new Intent(this.context, Alarm_Receiver2.class);
            pending_intent2 = PendingIntent.getBroadcast(Main2Activity.this,0,
                    my_intent2, PendingIntent.FLAG_UPDATE_CURRENT);
            //Alarm manager
            alarm_manager2.set(AlarmManager.RTC_WAKEUP, calendar2.getTimeInMillis(),
                    pending_intent1);
            break;

    }
}

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_ID)

        return new TimePickerDialog(Main2Activity.this, kTimePickerListener, hour_x, minute_x, true);
    return null;
}

protected TimePickerDialog.OnTimeSetListener kTimePickerListener =
        new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                hour_x = hourOfDay;
                minute_x = minute;
                Toast.makeText(Main2Activity.this, hour_x + ": " + minute_x, Toast.LENGTH_LONG).show();
            }
        };

这是我的xml:

<?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="wrap_content"
android:weightSum="2"
android:orientation="horizontal"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

<ImageButton
    android:layout_width="0dp"
    android:layout_height="400dp"
    android:layout_weight="1"
    android:id="@+id/botoAbdominals"
    android:background="@drawable/abdominals"
    android:contentDescription="ImatgeAbdominals"
    android:layout_marginTop="50dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    />


<ImageButton
    android:layout_width="0dp"
    android:layout_height="400dp"
    android:layout_weight="1"
    android:id="@+id/botoFlexio"
    android:layout_gravity="top"
    android:layout_marginTop="50dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/flexio"
    android:contentDescription="ImatgeFlexio"
    />

0 个答案:

没有答案