How to change the image of a View?

1

Cordial greeting,

I have a Navigation Drawer Activity and I have managed to change my font type of a Textview that is in a nav_header_options.xlm, from this it deletes the image. How to change the default image for another, this to take it into account for a next project I have.

nav_headeroptions.xlm

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="@string/title_activity_options"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:id="@+id/mi_title"/>    
</LinearLayout>

OptionsActivity.java

package com.windroid.dinas;

import ...

public class OptionsActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    GlobalVariables globalVariables;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        globalVariables = (GlobalVariables)getApplicationContext();
        getSupportActionBar().setTitle(globalVariables.getName());

/*      CAMBIA EL COLOR Y L LETRA DE LAS OPCIONES DE MENU  */
        View header =  navigationView.getHeaderView(0);
        header.getBackground().setColorFilter(Color.parseColor("#ff0101"), PorterDuff.Mode.DARKEN);
        TextView tx = (TextView) header.findViewById(R.id.mi_title);
        Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/milton.ttf");
        tx.setTypeface(custom_font);
        tx.setTextSize(TypedValue.COMPLEX_UNIT_SP,40);
        tx.setTypeface(tx.getTypeface(), Typeface.BOLD);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

    
asked by user2683734 05.03.2017 в 06:30
source

0 answers