0

I have this code in manifest

<activity
    android:name=".MyActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
    </intent-filter>
</activity>

How can i add click listener for TextView with "@string/app_name"? This is my label title.

alexbayker
  • 882
  • 9
  • 19

2 Answers2

1

As answered this already here, try adding this code under the onCreate() function. This will grab the resource the action bar title is under, and assign it an id you can use to add an OnClickListener to. Let me know how it goes!

final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
findViewById(abTitleId).setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    //Do something
    }
});
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
-1

In your Java activity class, type this following code.

TextView t = (TextView)findViewById(R.id.app_name);
t.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View view){
         */your code here*/
     }
});

Whatever code that's inside the listener is the code that's going to run when you click the textview.

SatvikVejendla
  • 424
  • 5
  • 14