Android Action Bar: Can I replace a custom Title in appcompat v7

后端 未结 3 1704
逝去的感伤
逝去的感伤 2021-01-21 04:05

I want to add a custom action title on the left of the actin bar, replacing with the default title just like in the below image the default image is shown

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-21 04:17

    It is very easy to do ..

    There's lot's of way to do this task as defined above .. but I will suggest to make use of custom view for Action bar(As this will work on all devices as same) .. this will let you create much more complex view's in a very handy and easy way.

    For your query you make make use of custom views for ActionBar..

    You can create customized action bar like this ..

    actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.xyz); // Set custom view like this 
    // In your case you want an icon ... 
    ImageView image = (ImageView) actionBar.getCustomView().findViewById(R.id.fare_ll); // Get id of custom view like this
    

    Also you need to set this property ..

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    
    // Now you can do any sort of stuffs with this icon .. like you can perform click functionality
    

    Here's your xyz.xml file .. This file is just for your reference purpose .. this will let you know how to create custom view for Action Bar. :)

    
    
    
         
    
            
    
            
    
            
    
            
            
    
        
    
         
    
        
         
         
        
       
    
    
    

    You are good to go ..

提交回复
热议问题