Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

116.3. UI 界面

116.3.1. Toast

	
Toast.makeText(getApplicationContext(), "默认Toast样式", Toast.LENGTH_SHORT).show();	  
	
		

116.3.1.1. 自定义样式

		
toast = Toast.makeText(getApplicationContext(),"自定义位置Toast", Toast.LENGTH_LONG);
   toast.setGravity(Gravity.CENTER, 0, 0);
   toast.show();
		
			

116.3.1.2. 带有图片的样式

		
toast = Toast.makeText(getApplicationContext(),"带图片的Toast", Toast.LENGTH_LONG);
   toast.setGravity(Gravity.CENTER, 0, 0);
   LinearLayout toastView = (LinearLayout) toast.getView();
   ImageView imageView = new ImageView(getApplicationContext());
   imageView.setImageResource(R.drawable.icon);
   toastView.addView(imageView, 0);
   toast.show(); 		
		
			

116.3.2. Dialog

		
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
                .setTitle("你问的是:")//设置对话框 标题
                .setIcon(R.drawable.icon)//设置图标
                .setMessage(prompt);

        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                aigcSpeech.say("创作中请稍后");
//                                    Toast.makeText(MainActivity.this,"you click 'yes' button ", Toast.LENGTH_SHORT).show();
                UUID uuid = UUID.randomUUID();
                session = uuid.toString();
                aigc.story(session, prompt, value -> {
                    Log.d(TAG, "Session: " + value + " Text: " + prompt);
                });
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "取消操作", Toast.LENGTH_SHORT).show();
                aigcSpeech.say("操作取消了");
            }
        });

        builder.create().show();		
		
		

116.3.3. DatePicker

         
        <DatePicker
        android:id="@+id/dp_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:calendarViewShown="false"
        android:datePickerMode="spinner"
        android:gravity="center"
        android:spinnersShown="true" />