Skip to content

Instantly share code, notes, and snippets.

View mahdimortazavi's full-sized avatar
☺️
happy

mahdi mortazavi mahdimortazavi

☺️
happy
View GitHub Profile
public void dialogView() {
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
LayoutInflater inflater = mActivity.getLayoutInflater();
View content = inflater.inflate(R.layout.dialog_layout_view, null);
builder.setView(content);
((TextView) content.findViewById(R.id.tv_onvan_view)).setText(R.string.dialog_onvan);
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@mahdimortazavi
mahdimortazavi / RTL Activity
Created June 13, 2016 13:37
rtl all views in activity
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
@mahdimortazavi
mahdimortazavi / menu item
Created June 14, 2016 15:25
app:showAsAction
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@id/item_menu_1"
android:icon="@drawable/icon_user"
app:showAsAction="ifRoom"
android:title="item 1" />
@mahdimortazavi
mahdimortazavi / Margin in Java
Last active June 18, 2016 07:43
margin and background color for Button
Button button=(Button)findViewById(R.id.button);
Button button2=(Button)findViewById(R.id.button2);
button.setBackgroundColor(getResources().getColor(R.color.grey_100));
button2.setBackgroundColor(getResources().getColor(R.color.grey_100));
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) button.getLayoutParams();
params.leftMargin=7;
params.rightMargin=7;
@mahdimortazavi
mahdimortazavi / Fullscreen Activity in Android
Created June 22, 2016 20:50
Fullscreen Activity in Android
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
@mahdimortazavi
mahdimortazavi / Change project name on Android Studio
Created June 22, 2016 21:00
Change project name on Android Studio
You can change the name that is shown in the title bar in the file ".idea/.name".
@mahdimortazavi
mahdimortazavi / change font all project
Last active July 19, 2016 20:19
change font all application
add dependency
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/irsensnumeral.ttf")
@mahdimortazavi
mahdimortazavi / Splash.java
Created June 28, 2016 13:17
Splash Screen Full Screen
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
@mahdimortazavi
mahdimortazavi / onCreateOptionsMenu & onOptionsItemSelected
Created July 16, 2016 09:13
Sample onOptionsItemSelected and onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.bookmark_menu:
Toast.makeText(this, "You have selected Bookmark Menu", Toast.LENGTH_SHORT).show();