How To Add Actionbaractivity In Android Project?
I'm not able to add ActionBarActivity in my Android project. There are no options of appcpmpat-v7 in any of my project. What i do now?
Solution 1:
public class MainActivity extends Activity {
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBarmActionBar= getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflatermInflater= LayoutInflater.from(this);
ViewmCustomView= mInflater.inflate(R.layout.custom_actionbar, null);
TextViewmTitleTextView= (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("My Own Title");
ImageButtonimageButton= (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(newOnClickListener() {
@Overridepublicvoid onCl`enter code here`ick(View view) {
Toast.makeText(getApplication`enter code here`Context(), "Refresh Clicked!",
Toast.LENGTH_LONG).show();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
}
Solution 2:
If this is a gradle based project then you can add the following dependency in your build.gradle file which will import this dependency.
compile'com.android.support:appcompat-v7:23.0.0'
PS: 23.0.0 is the latest version targeting android M. You can use 21 or 22 as well
Solution 3:
You should have dependency in your gradle file for com.android.support:appcompat-v7:21.0.0
And you mistyped name of class in question.
Solution 4:
You can find the answer here How to add suport library,ActionBarActivity and themes to android project? If your workspace does not contain appcompat, it will be automatically made by Eclipse.
Post a Comment for "How To Add Actionbaractivity In Android Project?"