Android нинг яратилиши тарихи


Download 57.67 Kb.
bet3/3
Sana11.10.2023
Hajmi57.67 Kb.
#1698062
1   2   3
Bog'liq
1-bilet

Menyu yaratish


Ilovalardagi menyular android.view.Menu klassi bilan ifodalanadi va har bir faoliyat ushbu turdagi ob'ekt bilan bog'lanadi. android.view.Menu obyekti o'zgaruvchan sonli elementlarni o'z ichiga olishi mumkin, ular o'z navbatida pastki elementlarni saqlashi mumkin.

2
3
4


5
6
7
8
9
10
11
12
13
14
15
16
17


xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >

android:id="@+id/selectedMenuItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="28sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />



package com.example.menuapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override


public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main_menu, menu);


return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
TextView headerView = findViewById(R.id.selectedMenuItem);
switch(id){
case R.id.action_settings :
headerView.setText("Настройки");
return true;
case R.id.open_settings:
headerView.setText("Открыть");
return true;
case R.id.save_settings:
headerView.setText("Сохранить");
return true;
}
//headerView.setText(item.getTitle());
return super.onOptionsItemSelected(item);
}
}
Download 57.67 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling