انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#1
سلام

دوستان و استادان گرامی مشکل کجاست که در برنامه آیکون های تعیین شده نمایش داده نمی شود؟

کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item
        android:id="@+id/action_help"
        android:title="@string/action_help"
        android:icon="@drawable/help"
        android:showAsAction="ifRoom"/>
    <item
        android:id="@+id/action_favorite"
        android:title="@string/action_favorite"
        android:icon="@drawable/help"
        android:showAsAction="ifRoom"/>

</menu> 

عکس help  در پوشه ی drawable hdpi و mdpi وجود دارد و سایزش 20*28 هستش.

Flower
پاسخ

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#2
سلام

لطفا محتوای فایلهای activity.java مربوطه و style.xml رو بزارید
پاسخ

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#3
سلام کدهای زیر رو هم باید به اکتیوتی مورد نظر اضافه کنید :

کد پی‌اچ‌پی:
 @Override
    public boolean onCreateOptionsMenu
(Menu menu) {
 
       super.onCreateOptionsMenu(menu);
 
       return true;
 
   }

 
   @Override
    public boolean onOptionsItemSelected
(MenuItem item) {
 
            int id item.getItemId();
 
            if(R.id.yourId){
 
                 //some code
 
           }else if() ...//other items
 
           return super.onOptionsItemSelected(item);
 
   
پاسخ
 سپاس شده توسط sohrabjam ، admin

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#4
سلام ممنون از پاسخ هاتون .
 دوستان گرامی کدهایی که گفتید همه رو گذاشتم و همه به خوبی کار میکند یعنی وقتی برنامه را اجرا می کنم ،اکشن بار در برنامه هست و آیتم ها هم هستند و کدها هم به خوبی کار میکنند تنها اشکالی که وجود دارد این است که آیکونی که طراحی کردم تا در جلو آیتم ها در اکشن باروجود داشته باشد نشان داده نمی شود. من در قسنت منو فایل لاگین در آیتم ها این کد را گذاشتم
کد پی‌اچ‌پی:
android:icon="@drawable/help" 

 
ولی در برنامه در جلو آیتم ها این آیکون نشان داده نمی شود.

کدهای menu->login.xml
کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item
        android:id="@+id/action_help"
        android:title="@string/action_help"
        android:icon="@drawable/help"
        android:showAsAction="ifRoom"/>
    <item
        android:id="@+id/action_favorite"
        android:title="@string/action_favorite"
        android:icon="@drawable/help"
        android:showAsAction="ifRoom"/>

</menu> 
string.xml
کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">آشپذ شو</string>
    <string name="title_section1">Section 1</string>
    <string name="title_section2">Section 2</string>
    <string name="title_section3">Section 3</string>
    <string name="navigation_drawer_open">Open navigation drawer</string>
    <string name="navigation_drawer_close">Close navigation drawer</string>
    <string name="action_example">Example action</string>
    <string name="action_settings">Settings</string>
    
    <string name="action_save">ذخیره</string>
    <string name="action_cancel">لغو</string>
    <string name="action_help">راهنما</string>
    <string name="action_favorite">علاقه مندی ها</string>

</resources> 
styles.xml
کد پی‌اچ‌پی:
<resources>

 
   <!--
 
       Base application themedependent on API levelThis theme is replaced
        by AppBaseTheme from res
/values-vXX/styles.xml on newer devices.
 
   -->
 
   <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
 
       <!--
 
           Theme customizations available in newer API levels can go in
            res
/values-vXX/styles.xml, while customizations related to
            backward
-compatibility can go here.
 
       -->
 
   </style>

 
   <!-- Application theme. -->
 
   <style name="AppTheme" parent="AppBaseTheme">
 
       <!-- All customizations that are NOT specific to a particular API-level can go here. -->
 
   </style>

</
resources
layout->login.xml
کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back1" >

    <TextView
        android:id="@+id/login_titr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:text="ورود"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/login_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="88dp"
        android:src="@drawable/main_cancel_kelid" />

    <ImageView
        android:id="@+id/login_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/login_cancel"
        android:src="@drawable/main_login_kelid" />

    <CheckBox
        android:id="@+id/login_cb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="مرا در حالت ورود نگه دار" />

    <EditText
        android:id="@+id/login_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_titr"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:ems="10"
        android:hint="نام کاربری" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/login_pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/login_cb"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="24dp"
        android:ems="10"
        android:hint="پسورد" />

</RelativeLayout> 

login.java
کد پی‌اچ‌پی:
package com.ata.Ashpazsho;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class 
login extends ActionBarActivity {
    
    private 
EditText usertext,passtext;
    private 
ImageView login,exit;
    private 
CheckBox cb;

    public static 
String res="";
    private 
int count=0;
    private 
SharedPreferences sp;
    
    
     @
Override
        protected void onCreate
(Bundle savedInstanceState) {
     
       super.onCreate(savedInstanceState);
     
       setContentView(R.layout.login);
        
        
         
       usertext =(EditTextfindViewById(R.id.login_user);
         
       passtext =(EditTextfindViewById(R.id.login_pass);
         
       
                
                login 
=(ImageViewfindViewById(R.id.login_login);
         
       exit =(ImageViewfindViewById(R.id.login_cancel);
         
       
                cb
=(CheckBoxfindViewById(R.id.login_cb);
         
       
                sp
=getApplicationContext().getSharedPreferences("userP"0);
         
       
                if
(sp.getInt("status"0)==1){
         
           
                    
                    Intent in
=new Intent(login.this,MainActivity.class);
         
           f();
         
           startActivity(in);
         
           
                    
                
}
         
       
                
                
                
                login
.setOnClickListener(new OnClickListener(){

         
                    @
Override
                    
public void onClick(View arg0) {
                        
// TODO Auto-generated method stub
                        
                        /*Intent in=new Intent(login.this,MainActivity.class);
                        startActivity(in);*/
                        
                    
if(!usertext.getText().toString().equals("")&& !passtext.getText().toString().equals("")){        
                        
                        if(
cb.isChecked()){
                            
                            
login1(usertext.getText().toString(),passtext.getText().toString(),1);
                            
                        }else{
                            
                            
                            
login1(usertext.getText().toString(),passtext.getText().toString(),0);
                            
                        }
                    }else{
                        
Toast.makeText(getApplicationContext(), "نام کاربری و پسورد را وارد نمایید!"Toast.LENGTH_SHORT).show();
                    }
                        
                            
                            
                            
                        
                        
                    }
            
         
       });
         
       
                
                exit
.setOnClickListener(new OnClickListener(){

                    @
Override
                    
public void onClick(View arg0) {
                        
finish();
                        
                    }
            
         
       });
         
       
                
             
            
}

         
   
            private void login1
(final String user,final String pass,final int status){
         
       
                
                
new LoginServer("http://ata.xzn.ir/logindf.php",user,pass).execute();
         
       
                
                
                
                
                
final ProgressDialog pd=new ProgressDialog(login.this);
         
       pd.setMessage("لطفا صبر کنید");
         
       pd.show();
         
       
                
                
                
                
                
                
                
                
final Timer tm=new Timer();
         
       tm.scheduleAtFixedRate(new TimerTask(){
                    public 
void run() {
                        
runOnUiThread(new Runnable(){
                            public 
void run() {
                                
                                
count++;
                                
                                if(
count==40){
                                    
                                    
pd.cancel();
                                    
tm.cancel();
                                    new 
LoginServer("http://ata.xzn.ir/logindf.php",user,pass).cancel(true);
                                    
Toast.makeText(getApplicationContext(), "خطا در برقراری ارتباط"Toast.LENGTH_LONG).show();
                                    
                                    
                                }
                                
                                
                                if(
res.equals("ok")){
                                    
                                    
pd.cancel();
                                    
                                    
sp=getApplicationContext().getSharedPreferences("userP"0);
                             
       Editor edit=sp.edit();
                             
       edit.putString("username"user);
                             
       edit.putInt("status"status);
                             
       edit.commit();
                                    
                                    
                                    
                                    
//Toast.makeText(getApplicationContext(), res, Toast.LENGTH_LONG).show();
                                    
                                    
Intent in=new Intent(login.this,MainActivity.class);
                                    
res="";
                                    
tm.cancel();
                                    
                                    
f();
                                    
                                    
startActivity(in);
                                    
                                }else if(
res.equals("wrong password")){
                                    
                                    
pd.cancel();
                                    
Toast.makeText(getApplicationContext(), "پسورد اشتباه است!!!"Toast.LENGTH_LONG).show();
                                    
res="";
                                    
tm.cancel();
                                    
                                    
                                }else if(
res.equals("no user")){
                                    
                                    
pd.cancel();
                                    
Toast.makeText(getApplicationContext(), "نام کاربری وجود ندارد!!!"Toast.LENGTH_LONG).show();
                                    
res="";
                                    
tm.cancel();
                                    
                                    
                                    
                                }
                            }
                        });
                        
                    }
            
         
       }, 11000);
         
       

            
}
         
   
            
            
            private void f
(){
         
       
                this
.finish();
         
       
            
}

         
  
            
@Override
            public boolean onCreateOptionsMenu
(Menu menu) {
         
       // Inflate the menu; this adds items to the action bar if it is present.
         
       getMenuInflater().inflate(R.menu.loginmenu);
         
       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();
         
       switch(id){
         
       case R.id.action_favorite:
         
           
                    
                    
                    
return true;
         
       case R.id.action_help:
         
           
                    AlertDialog
.Builder ad=new AlertDialog.Builder(this);
         
           ad.setTitle("راهنما");
         
           ad.setIcon(R.drawable.help);
         
           ad.setMessage("فیلدهای ستاره دار باید حتما کامل شوند.\n در صورتی که دانشجو هستید \n سایر فیلدها را نیز کامل نمایید.!");
         
           ad.setCancelable(true);
         
           ad.setPositiveButton("OK", new DialogInterface.OnClickListener(){
         
               public void onClick(DialogInterface dialogint which) {
                            
                        }
         
               
                    
});
         
           
                    
final AlertDialog alert=ad.create();
         
           alert.show();
         
           
                    
return true;
         
       case R.id.action_cancel:
         
           
                    finish
();
         
           
                    
return true;
         
       default:
         
           return super.onOptionsItemSelected(item);    
         
       }
         
       
            
}
         
   
            
            
        


Flower


فایل‌های پیوست

عکس(ها)
   
پاسخ

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#5
در این حالت اندروید آیکون های آیتم هارو نمایش نمیده
پاسخ

عدم نمایش آیکون در اکشن بار (Action Bar) (برنامه نویسی اندروید)

#6
سلام

در فایل Menu->login.xml

کد:
android:showAsAction="ifRoom"
رو به این تغییر بدید
app:showAsAction="ifRoom"


androidConfusedhowAsAction="ifRoom"  در API 11   به بالا پشتیبانی میشه که احتمال زیاد شما دارید از API کمتر از 11 استفاده می کنید
پاسخ
 سپاس شده توسط شماره مجازی امارات ، تلگرام ضد فیلتر 2023


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان